首页 > Web开发 > 详细

create a nodejs npm package

时间:2015-03-27 01:02:20      阅读:256      评论:0      收藏:0      [点我收藏+]

 

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

 

create a nodejs npm package

原文:http://www.cnblogs.com/zyip/p/4370370.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!