Running node or npm terminal commands Print

  • 0

Before you can run commands over SSH you will need to have requested your SSH access details from us. Please open a support ticket to request this. Alternatively you can run commands using the Terminal app in the web hosting control panel.

There are two scenarios where you might need to run npm commands; to manage a Node.js app, or for a regular website where you are using npm to build static assets such as css and javascript. Jump to the appropriate section in this article below:

Running npm commands for a Node.js app

Running npm commands for other websites

 

Running npm commands for a Node.js app

You might need to run a command for configuring or installing your Node.js app such as a npm install command.

This article assumes that you have already configured your Node.js app. Please see How to setup a Node.js app from the control panel

Each Node.js app runs inside it's own virtual environment. To run npm commands you will need to first enter the environment for your app.

1. From the Control Panel find and click on the Setup Node.js App icon.

2. You will see a list of your Node.js apps, click the pencil Edit icon next to your app.

3. You will see the configuration screen for your app. The command for entering the app environment is displayed at the top of this screen, run the command. The command will look something like this:

source /home/username/nodevenv/application-root/24/bin/activate && cd /home/username/nodevenv/application-root

4. Now run npm commands as you normally would.

5. You will need to restart your Node.js app to see changes; from the Control Panel, find and click on the Setup Node.js App icon and then click the Restart icon next to your app.

 

Running npm commands for other websites

You might need to run npm build commands to compile css, javascript and other static assets for your website. If you have followed our article on how to publish your website with Git, you could add your npm build commands to the hooks/post-receive script described in that article.

Before you can run npm commands you will need to set up a Node.js app, even though you are not running a Node.js app, configuring one is still required to install npm into your account. You should install your empty Node.js application in a location that won't interfere with your website. See How to setup a Node.js app from the control panel

Make a note of the node version and application root settings that you configured for your app, you will need these to locate your npm binary.

The npm binary will be found at:

~/nodevenv/<application root>/<node version>/bin/npm

So if your application root folder was set to "myapp" and your node version was set to 24, then to run "npm build" you would type:

~/nodevenv/myapp/24/bin/npm build

To save typing out the full path to npm for every command you could temporarily add the node bin folder to your $PATH. Run the following command before running your npm commands, you will only need to run this command once per session (replace <application root> and <node version>):

export PATH="~/nodevenv/<application root>/<node version>/bin:$PATH"


Was this answer helpful?

« Back