步骤
-
安装node.js
-
编写程序
目录结构
Project hello-world-project
- run.bat
- server.js
server.js
const http = require(‘http‘);
const hostname = ‘127.0.0.1‘;
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader(‘Content-Type‘, ‘text/plain‘);
res.end(‘Hello World‘);
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
run.bat
REM run in node.js runtime
node server.js
点击run.bat,服务器程序启动;
打开浏览器,地址栏输入:" 127.0.0.1:3030 ",观察页面。