create a nodejs npm package
1. create a folder named m1
2. run command: npm init, this will create the package.json file
3. create a lib folder using command: mkdir lib
4. create index.js using : touch index.js
5. run command : vim index.js , writing following content into it
module.exports=function(){ this.hi=function(){ console.log(‘hi in index‘); } console.log(‘index file in m1‘); }
6. type :w :q to save and quit editing mode
7. To install m1 module to your project , you can use command: npm install ../m1
8. To visit your module code
var ma1=require(‘../m1‘);// require(‘../m1/lib/a‘); var ma1ins=new ma1(); ma1ins.hi();
reference:
http://nqdeng.github.io/7-days-nodejs/#2.2.1
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。