【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
posted @ 2019-02-19 09:09  麦兜爱学习  阅读(535)  评论(0编辑  收藏  举报