Home >Web Front-end >HTML Tutorial >Common modules and usage
When nodejs implements http, no matter which part of the code is modified, nodejs must be terminated and re-run. will take effect. Because nodejs only goes back to parse the script file when a certain part is referenced for the first time, it will be accessed directly in the memory in the future to avoid repeated loading.
supervisor will monitor your code changes and automatically restart nodejs
Installation and configuration
# npm install -g supervisor # supervisor app.js 运行服务器 ,当代码改动的时候会自动加载
Node is a middleware framework that performs middleware management based on the web server, similar to java filters. In connect, several commonly used components are provided, which can be used for request logs, static file services, request body parsing, session management, etc.
Use, use the use method to register middleware into a queue of connect objects
app.use(connect.staticCache()); app.use(connect.static(__dirname + '/public')); app.use(connect.cookieParser()); app.use(connect.session()); app.use(connect.query()); app.use(connect.bodyParser()); app.use(connect.csrf()); app.use(function (req, res, next) { // 中间件 }); app.listen(3001); 复制代码
Flow chart, there must be a middleware The software calls the res.end()
method to inform the client that the request has been processed, otherwise the client will always be in a waiting state.
#This article explains common modules and their usage. For more related content, please pay attention to the PHP Chinese website.
Related recommendations:
Two tree array constructors without recursion
Convert HTML to Excel, and realize printing and downloading functions
The above is the detailed content of Common modules and usage. For more information, please follow other related articles on the PHP Chinese website!