快速入门步骤 🚀
-
创建项目
运行以下命令初始化项目:npm init -y
运行第一个请求
在项目目录中创建index.js
,并添加以下代码:const http = require('http'); http.createServer((req, res) => { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(3000, '127.0.0.1');
常见问题 ❓
Q:如何调试服务器?
A:使用node inspect index.js
启动调试模式,或添加日志输出。Q:如何部署到生产环境?
A:建议使用 PM2 进行进程管理,参考 /Guides/Deployment_Guide 获取详细说明。