我有错误,它在第1行字符1中显示语法错误

时间:2019-05-24 13:44:13

标签: node.js

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}/`);
});

//及其不起作用,向我显示语法错误 //如果有人可以告诉我如何解决此问题

1 个答案:

答案 0 :(得分:1)

不要双击您的js文件,您必须使用nodejs启动它:

  1. 下载nodejs
  2. 打开一个终端
  3. 使用cd命令移动到当前目录(文件所在的位置)
  4. 输入“ node yourfile.js”

您将在终端中获得程序的输出。