Node.js创建项目先新建一个文件夹cmd进入通过npm init命令生成 package.json 文件它包含了项目的配置信息。npm init -y把 package.json 文件修改为以下内容{name:0317,version:1.0.0,main:index.js,scripts:{start:node app.js//只改这里就可以了就可以运行了 start:node app.js},keywords:[],author:,license:ISC,description:}在项目根目录文件下创建一个app.jsconsthttprequire(http);// 创建服务器constserverhttp.createServer((req,res){// 设置HTTP响应的状态码和头信息res.writeHead(200,{// 设置内容类型为 HTML并指定字符集为 UTF-8这样中文不会乱码Content-Type:text/html; charsetutf-8});// 发送响应体res.end(h1Hello, World!/h1p这是我的第一个 Node.js 应用。/p);});// 监听端口constPORT3000;server.listen(PORT,(){console.log(Server is running on http://localhost:${PORT});});运行项目命令npm run start运行完成后会得到这个Server is running on http://localhost:3000点击运行可以了。运行完成后会得到这个Server is running on http://localhost:3000点击运行可以了。运行效果如下