How to share company npm modules internally Suppose you just wrote an amazing module that you want to break off into a package so it can be reused. The problem is that it contains some super-secret company stuff that can’t be shared and you can’t, or don’t want to, create a private npm organization. So what do you do now? node Believe it or not, if you’re using private git repositories then you already have everything that you need. Installing packages from git Installing packages with git is actually really easy, if you use github, gitlab, bitbucket. just requires a special package name to install from git. The format is . npm install SERVICE:user/repo So if your username is and you’re trying to install the repo from gitlab, then execute the following command: stan willzyx npm install gitlab:stan/willzyx How about versions? To install a specific tag or branch, add to the end of the package name. If you’re using to update your package version, then you can add to install the latest version of 1.x. #NAME npm version #semver:^1.0 What about complex packages? Sure, that’s great for plain-old packages, but what if you’re using something fancy like Typescript? How do you build the package without checking in the build artifacts to your repo? javascript The section of has a few special scripts that run as part of specific npm commands. The one you want to define is . This script is run after the package is installed. scripts package.json prepare To continue the typescript example, you could use the following prepare script: "prepare": "node_modules/.bin/tsc" Any development dependencies will be installed before the script is run, and cleaned up after. Now that it’s built, how do I cleanup? This one is also pretty easy if you use git. Just like git has the file, npm has a file. has the same format, and is applied after the prepare script has finished. This means you can add the source directory to and it will magically disappear after you’ve installed the package. .gitignore .npmignore .npmignore .npmignore Hopefully this article has encouraged you to create some packages of your own. If you have any other tips that I may have missed, please share them with me in the comments or on twitter. References install | npm Documentation scripts | npm Documentation
Share Your Thoughts