Express 4.x static resource directory settings:
// static file directory App.use ('/public', Express. Static(__dirname+'/public')); App.use ('/data ', Express. Static (__dirname+'/data'));
Http://www.domain.com/image/aaa.jpg Access to aaa.jpg var under the server public directory Express = require ("Express"), app = Express (); App.use ( ' /image ', Express. Static ' /public '));
Express 4.x fragmented knowledge points:
//Output static FilesRes.sendfile ("/views/index.html");//Set Output JSONhttp.Get("/haha/", Function (req, res) {//Set HTTP HeaderRes.setheader ('Content-type','Application/json'); Res.send ({a:123B:456});});//JumpRes.redirect ("http://google.com");//Nodejs Display the current directory:__dirname
Information on cookie operations in Express:
Https://github.com/expressjs/cookie-parser
// 1. Load the cookie module var cookieparser = require ('cookie-parser'); // 2. Activate Cookies App.use (Cookieparser ()); // 3. Get cookies in the requested Req Json.stringify (req.cookies);
The Cookie-session in Express
Https://github.com/expressjs/cookie-session
varCookiesession = require ('cookie-session'); App.use (Cookiesession ());//empty session # destroying a sessionReq.session =NULLvarExpress = require ('Express')varSession = Require ('cookie-session')varApp =Express () App.use (session ({keys: ['Key1','Key2'], Secureproxy:true //If you do SSL outside of node})) App.use (function (req, res, next) {varn = req.session.views | |0req.session.views= ++n res.end (n+' views')}) App.listen ( the)