如何安装Node.js环境

时间:2023-03-10 03:16:00
如何安装Node.js环境

一、在Windows系统下安装Node.js环境

1.   下载地址:官网http://nodejs.org/

2.    安装nodejs,根据自己情况,安装路径 D:\Program Files\nodejs

3.  安装相关环境

安装express需要调用 npm install express -g

Or直接修改全局路径

npm config set prefix "D:\Program Files\nodejs"

npm config set cache "D:\Program Files\nodejs\webapp_cache" (先建好webapp_cache目录)

键入:express socialserver (socialserver是随意起的工程名称)

在myserver里自动创建public、routes、views、app.js、package.json这几文件。

在myserver下新建helloworld.js

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Node.js\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

键入node helloworld.js

如何安装Node.js环境