1,新建一個文件夾 hello_npm
2, cmd 到這個文件夾路徑
3,npm init ( 建立一個 package.json 文件)
4, npm install math ( 安裝 和math 相關的包)
5, 打開 hello_npm 可以看到 node_modules 和 package.json 文件,打開 node_modules,其中有一個 math 包
接下來可以在我們的 js 文件中使用這個包
在根目錄中 新建一個 index.js 文件
index.js 中敲:
var math=require('math');
console.log(math);
console.log(math.add(1, 2));
可以看到運行結果:

就成功 使用了 從 npm 上下載下來的包