Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行时环境。以下是一些 Node.js 的常用命令:
package.json
中定义):package.json
中定义):module.js
中):module.js
中):main.js
中):main.js
中):npm install <package-name>
安装缺失的模块。sudo
(仅限 Unix 系统) 提升权限。以下是一个简单的 Node.js HTTP 服务器示例:
const http = require('http');
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
});
server.listen(3000, '127.0.0.1', () => {
console.log('Server running at http://127.0.0.1:3000/');
});
运行这个脚本:
node server.js
访问 http://127.0.0.1:3000/
将会看到 "Hello, World!"。
希望这些信息对你有所帮助!如果有更多具体问题,请随时提问。
领取专属 10元无门槛券
手把手带您无忧上云