After getting huge positive feedback on our last post in regards to installing a Nodejs application on Cloudways. we got tons of questions on how we can install and use some modules like pm2, bower, gulp etc on Cloudways. So in this post, we are going to share how you can install some packages on your Cloudways server.
We will assist you in the process of installing/using a Node module globally on your server, this is the best and the easiest way to run these packages. Kindly note that you can install, run and manage these modules via your server’s master user only, this guide is not applicable to application users.
Pre-Step: Customize your Shell Environment via .bash_aliases
Before we install any node modules on your Cloudways server the first thing is to customize your Shell Environment using .bash_aliases. Bash alias is a method of supplementing or overriding Bash commands with new ones. Now simply copy-paste the commands below on your server after logging in the server via SSH.
cd && echo "export PATH='$PATH:/home/master/bin/npm'" >> .bash_aliases cd ~ && echo "export NODE_PATH='$NODE_PATH:/home/master/bin/npm/lib/node_modules'" >> .bash_aliases npm config set prefix "/home/master/bin/npm/lib/node_modules"
Installing node packages globally via NPM
Now we will start installing node modules via NPM, we will cover the popular modules in our guide and if you have any other Node module that’s not mentioned on the list you can simply alter the mentioned commands to install your own module.
PM2 is an advanced process manager for production Node.js applications. Load balancer, logs facility, startup script, microservice management, at a glance.
cd && echo "alias pm2='/home/master/bin/npm/lib/node_modules/bin/pm2'" >> .bash_aliases npm install pm2@latest -g
cd && echo "alias gulp='/home/master/bin/npm/lib/node_modules/bin/gulp'" >> .bash_aliases npm install -g gulp
cd && echo "alias bower='/home/master/bin/npm/lib/node_modules/bin/bower'" >> .bash_aliases npm install -g bower
cd && echo "alias yarn='/home/master/bin/npm/lib/node_modules/bin/yarn'" >> .bash_aliases npm install yarn -g
The world’s most popular modern open-source publishing platform. A headless Node.js CMS used by Apple, Sky News, Tinder and thousands more.
cd && echo "alias ghost='/home/master/bin/npm/lib/node_modules/bin/ghost'" >> .bash_aliases npm install ghost -9
Post-Step: Activating Shell Environment for node modules.
After you have install any node modules simply restart your SSH session or login in a new Shell prompt and recheck your node modules you should be able to access them without any issue.
That’s it you have now learned how to install node modules globally on your Cloudways server.