Install npm packages on Elastic Beanstalk aws service instance globally.

First off I am going to assume three things…

  1. You know how to create an Elastic Beanstalk aws service instance with Node.js as the platform.
  2. You know how to create a key file (.pem) on aws console.
  3. You know how to login (ssh) to the instance using the key file.

Now the question, why would you need to install npm packages after the setup or after creating the instance. During the setup when you select the option to upload the source code (.zip) you are providing the package.json (npm packages are defined here) file from which all the packages are installed and available in node_modules. But what if some package is required to be installed at global level.

Elastic Beanstalk – Platform – Node.js

Below are the steps I used to install a package called html-pdf globally to the instance.

  1. Login to the instance.
    • $ssh -i pem/awsinstancekeypairname2.pem ec2-user@INSTANCE_NAME.com
  2. Switch to root user.
    • $sudo su
  3. Set path to node location
    • $export PATH=$PATH:/opt/elasticbeanstalk/node-install/node-v10.17.0-linux-x64/bin/
    • Note: Above node version and path of the node on you elastic beanstalk instance might be different.
  4. Install html-pdf package globally.
    • $npm install -g html-pdf
  5. Now link the installed package.
    • $npm link html-pdf
  6. Restart the app server / instance and you are done.

Published by Kumar Gandhi K

Hi! I’m Kumar and I live in Bangalore (IN) with my family. By profession I’m a Web Developer experienced in a vast variety of frameworks and technologies, like, HTML, CSS, JavaScript, Angular, Bootstrap… Using these i have built or sometimes maintained mid market and enterprise level applications. I worked for few software companies over the years and on few domains like finance, field-service and storage. I also did consulting job at one point. I am loyal and hard (or for better word smart) working individual. In my free time I read books, in fact I buy a lot of books hoping that some day I might find all the time in the world to read them and I also enjoy watching TV.

Leave a comment