Really! It is very easy...
npm stands for node package manager
In Breif
Every npm require one package.json
with name and version properties
{
"name": "string-seperator",
"version": "1.0.2"
}
Step 1 - npm account
the most important thing, just go and sign up
Step 2 - login to npm via CLI
I guess you have made an account there
So, go to your terminal and type
$ npm login
Step 3 - Initialize npm
You need to initialize your project in order to publish the package to the npm registry
To initialize your project, run the following command
$ npm init
It will look like this
{
"name": "PROJECT_NAME",
"version": "1.0.0",
"description": "PROJECT_DESCRIPTION",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "AUTHOR_NAME",
"license": "ISC"
}
Let's code
- Go to your root repository and create
index.js
- Now write the following code in your
index.js
function greet(string){
return "Hello, " + string;
}
module.exports = greet;
- tada, now you have completed the core part of the project π
Publishing the package to the npm registry
- Make sure to check all your code before publishing
- Now head up to
terminal
again π¨π»βπ»
$ npm publish --access public
Here --access public
is a scope that tells npm to publish your package to the npm registry publicly.
π
You made it, you can check out your published package from β
Make sure to check out: https://snowbit.bio.link/
Make sure to check out my YouTube Channel: https://www.youtube.com/channel/UCNTKqF1vhFYX_v0ERnUa1RQ
Top comments (1)
Interesting, really super easy!