Publishing Npm Package Privately

Developer Writings
1 min readAug 8, 2021

we can publish npm package in our own github.

Need to have account in npm registry. https://www.npmjs.com/

Create a github account if you don’t have previous.

login in to github account

Create a respository name of the package you want use .

Repository must be private.

Now Go to github settings, Go to developer settings, Generate token with some name.

Now create a folder <package_name>/ you can clone the repository created in github.

cd <package-name>

npm init — scope=<github_username>/<package_name>

it will create a package.json as follows

package.json

{

“name”: “@developerwritings/test-package”,

“version”: “1.0.0”,

“description”: “”,

“main”: “index.js”,

“scripts”: {

“test”: “echo \”Error: no test specified\” && exit 1"

},

“repository”: {

“type”: “git”,

“url”: “git+https://github.com/developerwritings/test-packages.git"

},

“author”: “”,

“license”: “ISC”,

“bugs”: {

“url”: “https://github.com/developerwritings/test-packages/issues"

},

“homepage”: “https://github.com/developerwritings/test-packages#readme",

“dependencies”: {

“test-package”: “0.0.1”

}

}

if you even created directly package.json you can update in the name.

create a filed called .npmrc

paste the following two lines

registry=https://npm.pkg.github.com/developerwritings

//npm.pkg.github.com/:_authToken=<auth_token_generated_in_developersettings>

commit your changes to github

then execute npm publish, if you got any error while publishing re verify from first.

After that go to other nodejs Project. npm install <package_name>

You can verify from node_modules.

add other files and publish again, but you need to change the version in the package.json

--

--