4 node: true
5rules:
6▶ eol-last: error
7 eqeqeq: [error, allow-null]
8 indent: [error, 2, { MemberExpression: "off", SwitchCase: 1 }]
· · ·
7▶ eqeqeq: [error, allow-null]
8 indent: [error, 2, { MemberExpression: "off", SwitchCase: 1 }]
9 no-trailing-spaces: error
· · ·
8▶ indent: [error, 2, { MemberExpression: "off", SwitchCase: 1 }]
9 no-trailing-spaces: error
10 no-unused-vars: [error, { vars: all, args: none, ignoreRestSiblings: true }]
· · ·
9▶ no-trailing-spaces: error
10 no-unused-vars: [error, { vars: all, args: none, ignoreRestSiblings: true }]
11 no-restricted-globals:
· · ·
10▶ no-unused-vars: [error, { vars: all, args: none, ignoreRestSiblings: true }]
11 no-restricted-globals:
12 - error
+ 1 more matches in this file
5* Improve HTML structure in `res.redirect()` responses when HTML format is accepted by adding `<!DOCTYPE html>`, `<title>`, and `<body>` tags for better browser compatibility - by [@Bernice55231](https://github.com/Bernice55231) in [#5167](https://github.com/expressjs/express/pull/5167)
6
7▶* When calling `app.render` with options set to null, the locals object is handled correctly, preventing unexpected errors and making the method behave the same as when options is omitted or an empty object is passed - by [AkaHarshit](https://github.com/AkaHarshit) in [#6903](https://github.com/expressjs/express/pull/6903)
8
9 ```js
· · ·
62* breaking:
63 * `res.status()` accepts only integers, and input must be greater than 99 and less than 1000
64▶ * will throw a `RangeError: Invalid status code: ${code}. Status code must be greater than 99 and less than 1000.` for inputs outside this range
65 * will throw a `TypeError: Invalid status code: ${code}. Status code must be an integer.` for non integer inputs
66 * deps: send@1.0.0
· · ·
65▶ * will throw a `TypeError: Invalid status code: ${code}. Status code must be an integer.` for non integer inputs
66 * deps: send@1.0.0
67 * `res.redirect('back')` and `res.location('back')` is no longer a supported magic string, explicitly use `req.get('Referrer') || '/'`.
· · ·
188
189 * remove:
190▶ - Remove Express 3.x middleware error stubs
191 * deps: router@~1.3.0
192 - Add `next("router")` to exit from router
· · ·
292 * Fix routing requests without method
293 * deps: body-parser@1.20.2
294▶ - Fix strict json error message on Node.js 19+
295 - deps: content-type@~1.0.5
296 - deps: raw-body@2.5.2
+ 109 more matches in this file
9- [downloads](./downloads) - Transferring files to client
10- [ejs](./ejs) - Working with Embedded JavaScript templating (ejs)
11▶- [error-pages](./error-pages) - Creating error pages
12- [error](./error) - Working with error middleware
13- [hello-world](./hello-world) - Simple request handler
· · ·
12▶- [error](./error) - Working with error middleware
13- [hello-world](./hello-world) - Simple request handler
14- [markdown](./markdown) - Markdown as template engine
29
30app.use(function(req, res, next){
31▶ var err = req.session.error;
32 var msg = req.session.success;
33 delete req.session.error;
· · ·
33▶ delete req.session.error;
34 delete req.session.success;
35 res.locals.message = '';
· · ·
36▶ if (err) res.locals.message = '<p class="msg error">' + err + '</p>';
37 if (msg) res.locals.message = '<p class="msg success">' + msg + '</p>';
38 next();
· · ·
77 next();
78 } else {
79▶ req.session.error = 'Access denied!';
80 res.redirect('/login');
81 }
· · ·
120 });
121 } else {
122▶ req.session.error = 'Authentication failed, please check your '
123 + ' username and password.'
124 + ' (use "tj" and "foobar")';
27 res.download(req.params.file.join('/'), { root: FILES_DIR }, function (err) {
28 if (!err) return; // file sent
29▶ if (err.status !== 404) return next(err); // non-404 error
30 // file for download not found
31 res.statusCode = 404;
15app.set('view engine', 'ejs');
16
17▶// our custom "verbose errors" setting
18// which we can use in the templates
19// via settings['verbose errors']
· · ·
19▶// via settings['verbose errors']
20app.enable('verbose errors');
21
· · ·
20▶app.enable('verbose errors');
21
22// disable them in production
· · ·
23▶// use $ NODE_ENV=production node examples/error-pages
24if (app.settings.env === 'production') app.disable('verbose errors')
25
· · ·
24▶if (app.settings.env === 'production') app.disable('verbose errors')
25
26silent || app.use(logger('dev'));
+ 15 more matches in this file
1▶<%- include('error_header') -%>
2<h2>Error: <%= error.message %></h2>
3<% if (settings['verbose errors']) { %>
· · ·
2▶<h2>Error: <%= error.message %></h2>
3<% if (settings['verbose errors']) { %>
4 <pre><%= error.stack %></pre>
· · ·
3▶<% if (settings['verbose errors']) { %>
4 <pre><%= error.stack %></pre>
5<% } else { %>
· · ·
4▶ <pre><%= error.stack %></pre>
5<% } else { %>
6 <p>An error occurred!</p>
· · ·
6▶ <p>An error occurred!</p>
7<% } %>
8<%- include('footer') -%>
12if (!test) app.use(logger('dev'));
13
14▶// error handling middleware have an arity of 4
15// instead of the typical (req, res, next),
16// otherwise they behave exactly like regular
· · ·
18// in different orders etc.
19
20▶function error(err, req, res, next) {
21 // log it
22 if (!test) console.error(err.stack);
· · ·
22▶ if (!test) console.error(err.stack);
23
24 // respond with 500 "Internal Server Error".
· · ·
24▶ // respond with 500 "Internal Server Error".
25 res.status(500);
26 res.send('Internal Server Error');
· · ·
26▶ res.send('Internal Server Error');
27}
28
+ 6 more matches in this file
17app.set('view engine', 'ejs');
18
19▶// set views for error and 404 pages
20app.set('views', path.join(__dirname, 'views'));
21
· · ·
78app.use(function(err, req, res, next){
79 // log it
80▶ if (!module.parent) console.error(err.stack);
81
82 // error page
· · ·
82▶ // error page
83 res.status(500).render('5xx');
84});
4 <meta charset="utf-8">
5 <meta name="viewport" content="width=device-width,initial-scale=1">
6▶ <title>Internal Server Error</title>
7 <link rel="stylesheet" href="/style.css">
8 </head>
· · ·
9 <body>
10▶ <h1>500: Internal Server Error</h1>
11 <p>Looks like something blew up!</p>
12 </body>
5 */
6
7▶var createError = require('http-errors')
8var express = require('../../');
9var app = module.exports = express();
· · ·
24 req.params[name] = parseInt(num, 10);
25 if( isNaN(req.params[name]) ){
26▶ next(createError(400, 'failed to parseInt '+num));
27 } else {
28 next();
· · ·
37 next();
38 } else {
39▶ next(createError(404, 'failed to find user'));
40 }
41});
44 },
45 show: function(req, res){
46▶ res.send(users[req.params.id] || { error: 'Cannot find user' });
47 },
48 destroy: function(req, res, id){
· · ·
70// curl http://localhost:3000/users -- responds with all users
71// curl http://localhost:3000/users/1 -- responds with user 1
72▶// curl http://localhost:3000/users/4 -- responds with error
73// curl http://localhost:3000/users/1..3 -- responds with several users
74// curl -X DELETE http://localhost:3000/users/1 -- deletes the user
30 next();
31 } else {
32▶ next(new Error('Failed to load user ' + req.params.id));
33 }
34}
· · ·
41 } else {
42 // You may want to implement specific exceptions
43▶ // such as UnauthorizedError or similar so that you
44 // can handle these can be special-cased in an error handler
45 // (view ./examples/pages for this)
· · ·
44▶ // can handle these can be special-cased in an error handler
45 // (view ./examples/pages for this)
46 next(new Error('Unauthorized'));
· · ·
46▶ next(new Error('Unauthorized'));
47 }
48}
· · ·
53 next();
54 } else {
55▶ next(new Error('Unauthorized'));
56 }
57 }
41 await db.sAdd('cat', 'luna');
42 } catch (err) {
43▶ console.error('Error initializing Redis:', err);
44 process.exit(1);
45 }
· · ·
55 .then((vals) => res.send(vals))
56 .catch((err) => {
57▶ console.error(`Redis error for query "${query}":`, err);
58 next(err);
59 });
9var app = module.exports = express();
10
11▶// create an error with .status. we
12// can then use the property in our
13// custom error handler (Connect respects this prop as well)
· · ·
13▶// custom error handler (Connect respects this prop as well)
14
15function error(status, msg) {
· · ·
15▶function error(status, msg) {
16 var err = new Error(msg);
17 err.status = status;
· · ·
16▶ var err = new Error(msg);
17 err.status = status;
18 return err;
· · ·
32
33 // key isn't present
34▶ if (!key) return next(error(400, 'api key required'));
35
36 // key is invalid
+ 4 more matches in this file
144 * Dispatch a req, res pair into the application. Starts pipeline processing.
145 *
146▶ * If no callback is provided, then default error handlers will respond
147 * in the event of an error bubbling through the stack.
148 *
· · ·
147▶ * in the event of an error bubbling through the stack.
148 *
149 * @private
· · ·
154 var done = callback || finalhandler(req, res, {
155 env: this.get('env'),
156▶ onerror: logerror.bind(this)
157 });
158
· · ·
211
212 if (fns.length === 0) {
213▶ throw new TypeError('app.use() requires a middleware function')
214 }
215
· · ·
294app.engine = function engine(ext, fn) {
295 if (typeof fn !== 'function') {
296▶ throw new Error('callback function required');
297 }
298
+ 7 more matches in this file