Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull req #5284

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/error/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ app.get('/', function () {
throw new Error('something broke!');
});

app.get('/', function (err,req,res) {
// err and req and res perams pass
throw new Error('something Want wrongeÏ!');
});

app.get('/next', function(req, res, next){
// We can also pass exceptions to next()
// The reason for process.nextTick() is to show that
Expand Down
16 changes: 10 additions & 6 deletions examples/hello-world/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
'use strict'
'use strict';

var express = require('../../');
const express = require('express');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change this reference

var app = module.exports = express()
const app = express();

app.get('/', function(req, res){
app.get('/', (req, res) => {
res.send('Hello World');
});

/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
const port = process.env.PORT || 3000; // Use the provided port or default to 3000
app.listen(port, () => {
console.log(`Express started on port ${port}`);
});
}

module.exports = app; // Export the Express app to use it elsewhere
42 changes: 30 additions & 12 deletions examples/multi-router/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
'use strict'
'use strict';

var express = require('../..');
const express = require('express');
const app = express();
const port = 3000;

var app = module.exports = express();
// Use JSON parsing middleware for incoming requests
app.use(express.json());

app.use('/api/v1', require('./controllers/api_v1'));
app.use('/api/v2', require('./controllers/api_v2'));
// Define your API routes
const apiV1Router = require('./controllers/api_v1');
const apiV2Router = require('./controllers/api_v2');

app.get('/', function(req, res) {
res.send('Hello from root route.')
app.use('/api/v1', apiV1Router);
app.use('/api/v2', apiV2Router);

// Define a root route
app.get('/', (req, res) => {
res.send('Hello from root route.');
});

// Handle 404 errors (route not found)
app.use((req, res, next) => {
res.status(404).send('Not Found');
});

/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}
// Handle other errors
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Internal Server Error');
});

// Start the server
app.listen(port, () => {
console.log(`Express Server Started on port ${port}`);
});
Loading