02 从npm上下载一个包,并在 js 文件中使用这个包

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 包

 

扫描二维码关注公众号,回复: 9617541 查看本文章

 

 接下来可以在我们的 js 文件中使用这个包

在根目录中 新建一个 index.js 文件

index.js 中敲:

var math=require('math');
console.log(math);
console.log(math.add(1, 2));
可以看到运行结果:

就成功 使用了  从 npm 上下载下来的包 

猜你喜欢

转载自www.cnblogs.com/shanlu0000/p/12425638.html
今日推荐