1.安装hotnode插件
npm install -g hotnode
(淘宝镜像cnpm install -g hotnode)
2.部署web项目
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<h1>这是Node.js服务</h1>');
res.end("<p>I'm Lenhart</p>")
}).listen(5858);
3.访问地址:http://127.0.0.1:5858/
$ hotnode server.js
4.修改server.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<h1>这是Node.js服务</h1>');
res.end("<p>I'm Lenhart12312312121212qwe</p>")
}).listen(5858);
5.再次访问:http://127.0.0.1:5858/
$ hotnode server.js
hotnode node process restarted
hotnode server.js has been changed

本文介绍如何通过Hotnode插件安装、部署并热更新一个简单的Node.js Web项目。首先,利用Hotnode进行环境搭建;接着,创建了一个基本的HTTP服务,并演示了如何在浏览器中访问它;最后,展示了如何通过修改文件来触发服务的热更新。

被折叠的 条评论
为什么被折叠?



