There was a time prior to Express 4.0 that most of the middleware listed was part of Express with Connect, however this is now a separate project. The following are basic middlewares dependencies to help wtih a basic webapp scaffold.
1. Connect
npm install --save connect
const connect = (require(connect));
This provides:
basicAuth - basic access authorization for HTTPS and for easy development.
app.use(connect.bascAuth)();
body-parser - parses json and urlencoded, for handling forms and AJAX request. You may have to install this separate as not part of Connect 3.0^
npm install --save body-parser
app.use(require(bbody-parser)() );
compress - uses gzip to compress data good for slower mobile connections.
app.use(connect.compress);
directory - directory support for static files
directory (app.use(connect.directory());
2. Formidable
npm install --save formidable
const formidable = require('formidable');
helpful for file uploads.
//example
app.post('/profiles/myPic', function(req, res) {
let form = new formidable.IncomingForm();
form.parse(req, function, fields, files) {
//...do something
res.redirect(303, '/file-uploaded');
});
});
3. Cookie-parser
npm install --save cookie-parser
app.use(require(cookie-parser)(your secret goes here);
Easy for cookie management.
4. Express-session
npm install --save express-session
app.use(require(express-session)() );
Good for session IDs development only.
5. csurf
npm install --save csurf
app.use(require(csurf)());
Protects against Cross-site request forgery attacks. Link after express-session.
6. errorhandler
npm install --save errorhandler
app.use(require(errorhandler)());
Good for development error handling
7. morgan
npm install --save morgan
app.use(require(morgan)());
Logs all requests.
8. method-override
npm install --save method-override
app.use(require(method-override)());
Good for writing and testing APIs.
9. response-time
npm install --save response-time
app.use(require(response-time)());
Helps performance tuning, gives response header an X-Response.
10. vhost
npm install --save vhost
const vhost = require(vhost);
Helpful to manage subdomains in Express.