Node.js 入门
先下载Node.js环境
https://nodejs.org/zh-cn/download
编辑先用sublime Text
然后编辑
const http = require('http'); const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8', 'Cache-Control': 'no-cache' }); res.end('Hello World 我的妈耶!好好好 😌\n'); }); const PORT = 1337; const HOST = '127.0.0.1'; server.listen(PORT, HOST, () => { console.log(`Server running at http://${HOST}:${PORT}/`); }); // 添加优雅关闭处理 process.on('SIGTERM', () => { server.close(() => { console.log('Server closed'); process.exit(0); }); });
然后在浏览器的网址填入:
http://127.0.0.1:1337/
即可输出
Hello World 我的妈耶!好好好 😌
然后发现修改代码不能刷新输出,必须再走一遍才有效,为此我们继续引入一个forever让node.js应用后台执行
或者使用superVision
直接使用PM2吧
用DeepSeek辅助即可