1.简单服务器
const http = require("http")
cp = require('child_process'); //自动打开浏览器
var server = http.createServer(function (req, res) {
res.writeHead(200, {
"content-Type": "text/plain"
});
res.write("hello world");
res.end()
})
server.listen(3000, 'localhost', function () {
const host = server.address().address
const port = server.address().port
console.log("应用实例,访问地址为 http://%s:%s", host, port)
})
cp.exec('start http://localhost:3000/');
复制代码