Publishing your own npm package to github
Here are simple steps to setup your first npm package. You do not need to publish directly to npm repository instead you can push to git.
First thing you gotta do is - setup github.
a) Create a new repository and clone it to your local drive
b) Execute 'npm init'.
c) We will also use index.js as the default entry point. This means we will create a file called "index.js" and it will host our modules, which might looks something like this :-
It just provide function to call and execute hello.
d) Commit our code changes with git and then issue the following command to make master as the default branch in git.
git push origin master
e) Next, create any new folder and issue the following command to see if we can install our package correctly.
npm install git://github.com/appcoreopc/hellonpm.git
f) To verify, type the following on node command line.
node
and then let's call our library into action with the follow codes.
var a = require('hellonpm').hello;
a('jeremy')
If you wanna push to npm, first you gotta have an account and pay them some money. The command to upload is really easy :-
npm publish
Comments