[英]How publish and use the npm packages
npmpublicrepo -- package.json -- test.js
package.json
{
"name": "npmpublicrepo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
test.js
exports.testMessage = function() {
console.log("test");
};
npm发布
这已成功发布,我可以在npm中看到页面
https://www.npmjs.com/package/npmpublicrepo
npmpublicrepousage -- package.json -- index.js
package.json
{
"name": "npmpublicrepousage",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"npmpublicrepo": "^1.0.0"
}
}
完成npm install
,我可以在./node_modules/npmpublicrepo
看到该文件夹,并且能够正确看到该模块的代码。
然后,我在脚本./index.js
使用上一个模块:
var test = require("npmpublicrepo");
test.testMessage();
但是,运行脚本失败:
节点./index.js
...出现错误:
module.js:472
throw err;
^
Error: Cannot find module 'npmpublicrepo'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/vimalprakash/Documents/Projects/NodeJs/npmpublicrepousage/index.js:1:74)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
我不知道我在想什么。
我的节点版本:v7.4.0
我的NPM版本:4.0.5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.