Labels

Linux (6) OpenCV (4) Deep Learning (3) MATLAB (3) Mac OS X (3) Windows (2) C# (1) Node JS (1)

2014年8月26日 星期二

Using HTTP basicAuth, bodyParser, cookieParser and other modules in ExpressJS 4.0

ExpressJS 4.0 removes all middlewares and make them independent packages. Therefore we cannot use ExpressJS 3.0 code directly. For basicAuth, some people implement their own version of HTTP basic authentication. But I think the easiest way is to use npm to install "basic-auth-connect" module:

var basicAuth = require('basic-auth-connect');
app.use(basicAuth('username', 'password'));

Follow the same rule, just install the necessary modules then we can use the old 3.0 codes! But the names of the new modules are different from original ones. The complete mapping table is as below (thanks to  Chris Sevilleja):

Express 3.0 NameExpress 4.0 Name
bodyParserbody-parser
compresscompression
cookieSessioncookie-session
loggermorgan
cookieParsercookie-parser
sessionexpress-session
faviconstatic-favicon
response-timeresponse-time
error-handlererrorhandler
method-overridemethod-override
timeoutconnect-timeout
vhostvhost
csrfcsurf

沒有留言:

張貼留言