Loading... ## 从哪开始? * [https://www.runoob.com/nodejs/nodejs-tutorial.html](https://www.runoob.com/nodejs/nodejs-tutorial.html) ## 第一个demo * **创建一个demo.js ** ``` console.log('hello world) ``` * **在终端中输入node demo.js 终端显示hello world** ## 第一个应用 * **新建一个app.js文件** * **引入require模块** * **粘贴如下代码** ``` 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}/`); }); ``` * **node app.js 运行程序**  * **端口被占用,更换一个** 最后修改:2022 年 05 月 13 日 © 允许规范转载 打赏 赞赏作者 赞 0 如果觉得我的文章对你有用,请随意赞赏