【nodejs】简单的httpserver
npm i chalk
const http = require('http');
const chalk = require('chalk');
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.write('Hello Nodejs Http...');
res.end();
});
server.listen(8080, '127.0.0.1', () => {
const addr = `http://127.0.0.1:8080`;
console.info(`Server started at ${chalk.green(addr)}`);
})
顺别提一下,使用supervisor自动监控文件变化,可以自动重启。
npm i -g supervisor
supervisor test.js