What does ‘extended’ mean in express 4.0?
If extended is false, you can not post “nested object” person[name] = ‘cw’ // Nested Object = { person: { name: cw } } If extended is true, you can do whatever way that you like.
If extended is false, you can not post “nested object” person[name] = ‘cw’ // Nested Object = { person: { name: cw } } If extended is true, you can do whatever way that you like.
It is optional and remain for legacy reason, according to the doc. In your example, the two piece of codes have no difference at all. http://expressjs.com/api.html#app.configure Update 2015: @IlanFrumer points out that app.configure is removed in Express 4.x. If you followed some outdated tutorials and wondering why it didn’t work, You should remove app.configure(function(){ … … Read more
Paths specified with a . are relative to the current working directory, not relative to the script file. So the file might be found if you run node app.js but not if you run node folder/app.js. The only exception to this is require(‘./file’) and that is only possible because require exists per-module and thus knows … Read more
As you mentioned, both req.locals, res.locals or even your own defined key res.userData can be used. However, when using a view engine with Express, you can set intermediate data on res.locals in your middleware, and that data will be available in your view (see this post). It is common practice to set intermediate data inside … Read more
The short story The trick in this case is not to initialize the model in the file but just to provide the necesary information for its initialization and let a centralized module take care of the models setup and instantiation. So the steps are: Have several Model files with data about the model, like fields, … Read more
You don’t export anything in your app module. Try adding this to your app.js file: module.exports = server
I found that the mongoose ObjectId validator works to validate valid objectIds but I found a few cases where invalid ids were considered valid. (eg: any 12 characters long string) var ObjectId = require(‘mongoose’).Types.ObjectId; ObjectId.isValid(‘microsoft123’); //true ObjectId.isValid(‘timtomtamted’); //true ObjectId.isValid(‘551137c2f9e1fac808a5f572’); //true What has been working for me is casting a string to an objectId and then … Read more
If it’s for a (few) specific extension(s), you can add your own require.extensions handler: var fs = require(‘fs’); require.extensions[‘.txt’] = function (module, filename) { module.exports = fs.readFileSync(filename, ‘utf8’); }; var words = require(“./words.txt”); console.log(typeof words); // string Otherwise, you can mix fs.readFile with require.resolve: var fs = require(‘fs’); function readModuleFile(path, callback) { try { var … Read more
In sequelize you can easily add order by clauses. exports.getStaticCompanies = function () { return Company.findAll({ where: { id: [46128, 2865, 49569, 1488, 45600, 61991, 1418, 61919, 53326, 61680] }, // Add order conditions here…. order: [ [‘id’, ‘DESC’], [‘name’, ‘ASC’], ], attributes: [‘id’, ‘logo_version’, ‘logo_content_type’, ‘name’, ‘updated_at’] }); }; See how I’ve added the … Read more
Use connect-redis and have redis as your session store for all authenticated users. Make sure on authentication you send the key (normally req.sessionID) to the client. Have the client store this key in a cookie. On socket connect (or anytime later) fetch this key from the cookie and send it back to the server. Fetch … Read more