const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
if(req.url!='/favicon.ico'){ //过滤favicon请求
console.log('request received!');
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
var name='rod johnson';
res.end(`Hello
${name}`);
}
}
);
server.listen(port, hostname, () => {
console.log(`服务运行于: http://${hostname}:${port}/`);
});