1.安装Node
在我之前的文章Windows系统下安装fis3中提到过怎么安装Node
2.打开cmd输入:
mkdir %USERPROFILE%\projects
cd %USERPROFILE%\projects
3.创建一个js脚本 hello-world.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!\n‘);
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
4.保存返回cmd执行node hello-world.js
5.控制台会输出
Server running at http://127.0.0.1:3000/
6.打开浏览器,在地址栏输入:
http://127.0.0.1:3000
原文地址:https://www.cnblogs.com/hros/p/10970122.html
时间: 2024-11-06 03:50:01