const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {//i create the server
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');//log to the console
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
//及其不起作用,向我显示语法错误 //如果有人可以告诉我如何解决此问题
答案 0 :(得分:1)
不要双击您的js文件,您必须使用nodejs启动它:
您将在终端中获得程序的输出。