Too many NPM libraries are demanding to be globally installed, to name a few:
npm install -g serverless
npm install -g terraform
npm install -g mocha
While it's sometimes very useful to have some of these components globally available,
in many cases you only need them for 1-2 projects.
In some cases, you might not have
permissions to install packages globally.
The reality is, you don't need to install them globally at all!
Installing a global NPM package locally
Let's take
Serverless as an example.
Let's say we want to deploy an existing project, but we don't have Serverless installed on our system.
First we install the package locally:
Then, on our
node_modules/ directory, there's a hidden
.bin/ directory, where the serverless binary is located.
So from the main project directory, we simply run:
./node_modules/.bin/serverless deploy -v
Now if you want to make it a bit more snappy, you could add a shortcut (i.e. symbolic link) to the binary:
ln -s node_modules/.bin/serverless serverless
And from now on simply run any serverless command like so:
On rare occasions, some packages' binaries are not under
node_modules/.bin/ but somewhere inside the package's directory, such as
node_modules/serverless/bin/.
So far I've been using locally installed packages for Serverless, SailsJS, Mocha, Terraform, and a few others as well.
On the next post, we'll try playing around with Serverless and S3, stay tuned!