1, create a new folder hello_npm
2, cmd into this folder path
3, npm init (establish a package.json file)
4, npm install math (math installation and related packages)
5, and open hello_npm see node_modules package.json file, open node_modules, a math package which has
Then you can use this package in our js file
Create a new file in the root directory index.js
index.js in knock:
var math=require('math');
console.log(math);
console.log(math.add(1, 2));
You can see the results:
It is used successfully downloaded from the npm package down