create a nodejs npm package

zyip發表於2015-03-26

 

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

 

相關文章