转到项目目录
mkdir TestProjectcd TestProject
将此目录设置为项目的根目录(这将创建一个默认
package.json文件)
npm init --yes
安装所需的npm模块并将其另存为项目依赖项(它将出现在中
package.json)
npm install request --save
test.js使用包示例中的代码在项目目录中创建文件
var request = require('request');request('http://www.google.com', function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body); // Print the google web page. }});您的项目目录应如下所示
TestProject/- node_modules/- package.json- test.js
现在只需在项目目录中运行节点
node test.js



