When I added a linter to my code, I noticed I got a lot of errors regarding 'use strict';
so I added the line to a lot of files. However this broke some code in my main app.js
file, which looks like this:
'use strict';
var express = require('express');
var timeout = require('connect-timeout');
//var logger = require('morgan');
var requireDir = require('require-dir');
var app = express();
// Load all the routes in the routes file into app middleware
// This assumes that the route exports an express.Router() object
var routes = requireDir('./routes');
for (var i in routes) app.use('/', routes[i]);
// Set the timeout
app.use(timeout('5s'));
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = 'ERROR: Invalid request to the server';
err.status = 404;
next(err);
});
if (!module.parent) {
app.listen(3000);
console.log('engine-map-service opend on port 3000');
}
Which returns the following error
stack:
TypeError: Cannot assign to read only property 'status' of ERROR: Invalid request to the server
at /usr/src/app/app.js:21:14
at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:312:13)
at /usr/src/app/node_modules/express/lib/router/index.js:280:7
at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:330:12)
at next (/usr/src/app/node_modules/express/lib/router/index.js:271:10)
at /usr/src/app/node_modules/connect-timeout/index.js:64:5
at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:312:13)
at /usr/src/app/node_modules/express/lib/router/index.js:280:7
What exactly is use strict
? I have read a few articles and I haven't seen anything going in depth about how I might need to change my behavior as a developer, and when I should or shouldn't use it. I found more than one article which recommended starting every js
file with use strict
but clearly there are cases which I am missing.