aka:JavaScript:Express
This note uses the section names of 'Node.js in Action' Chapter 8. However, the content is mostly my original.
- Generating application skeletons
- Express has its own (scaffold) generator, which you can install by 'npm install -g express-generator.'
- For the detail see http://expressjs.com/guide.html#executable
- Express has its own (scaffold) generator, which you can install by 'npm install -g express-generator.'
- Configuring Express and your application
- The use case of this section is: you want to change the behaviour of logger according to your app is running on a development environment or a production environment.
- Express provides a mechanism to achieve this use case, which uses the NODE_ENV system environment variable and the app.configure(). For instance,
$ NODE_ENV=development node app
app.configure(function() { // This is for all environments. app.set('view engine', 'ejs'); }; app.configure('development', function() { // This is for development only. app.use(express.errorHandler()); };
- Rendering views
- Express comes without a view engine. You can set up your Express application to use no, one, or multiple view engine(s). For the detail, see http://expressjs.com/4x/api.html#app.engine
- Some template engines don't implement interfaces to work with Express. But you can use some of them with the help of the consolidate module. https://www.npmjs.org/package/consolidate
- Here is the list of view engines you can use in Express. (Some require the consolidate module.)
atpl dust eco ect ejs haml haml-coffee handlebars hogan jade jazz jqtpl JUST liquor lodash mustache nunjucks QEJS ractive swig templayed toffee underscore walrus whiskers
- Handling forms and file uploads
- Handling resource downloads