Nodejs and NPM on hypernode (to use gulp, sass, compass, less, grunt-cli etc)

in Tools

Update 18-08-2016: We decided to pre-install nodejs on all hypernodes due to growing demand. You can still choose to install the most recent version by downloading the preinstalled version from the nodejs website, but a nodejs installation is present on the node itself already.

Using the installed version of Nodejs

If you use the installed version, you can just start using node and npm.

Setting your PATH

If you want to execute the tools that you installed using npm, you should make sure these executables can be located by the shell. This can be easily done this by adjusting your PATH setting.

This PATH variable is used by the Bash shell to locate binaries and scripts. You can adjust it by exporting the PATH variable:

export PATH="/data/web/node_modules/.bin:$PATH"

If you want this setting to be configured every time you log in to your hypernode, you can add this setting to your ~/.profile, this file is loaded every time a new shell is spawned.

To configure your PATH variable at login time, run the following command:

echo 'export PATH="/data/web/node_modules/.bin:$PATH"' >> ~/.profile

Now every time you log in, the Bash shell is configured to look for tools in /data/web/node_modules/.bin and /data/web/.node/bin.

Installing packages

Lets install some packages.

When your PATH is setup correctly, after the installation with npm install, you should immediately be able to use the newly installed tool.

To find the latest command line tool installed, run: ls -ltr /data/web/node_modules/.bin | tail -1

Install gulp

npm install gulp gulp-cli

Install grunt

npm install grunt grunt-cli

Install sass

npm install sass

Install compass

npm install compass

Install less

npm install less

You see the pattern here i presume? 🙂

Install yarn

To install yarn, a more recent version of nodejs is required, so follow the instructions and download and unpack a newer version of nodejs first

npm install yarn

Using a newer version of NodeJs

Install a newer version of Nodejs

If you want to use a more recent version, it is very easy to install the latest Nodejs yourself.

NodeJs offers precompiled packages on their website that are ready to use on your hypernode.
All we need to do is download and unpack them to make use of node and npm and install your own node modules.

In this example we use version v4.4.5 but the installation process is the same when using older or newer versions.

  • First, create the directory where we will unpack nodejs:
    mkdir /data/web/.node
    
  • Then, get the precompiled package from the NodeJS Website and unpack it in our directory:
    wget https://nodejs.org/dist/v4.4.5/node-v4.4.5-linux-x64.tar.xz -O /tmp/node.txz
    cd ~/.node && tar xvfJ /tmp/node.txz -C . --strip-components=1
    rm /tmp/node.txz
    

That’s it 🙂 you now have a precompiled node installation in ~/node

Configure a manually installed NodeJs

To run the manually installed executables, you need to change your PATH variable to make sure your node is located by the Bash shell before the pre-installed version.

To do this, run the following command to add the locations to your PATH:

export PATH="/data/web/node_modules/.bin:/data/web/.node/bin:$PATH"

Or to make the settings permanent, add it to your ~/.profile:

echo 'export PATH="/data/web/node_modules/.bin:/data/web/.node/bin:$PATH"' >> ~/.profile

Both the installations (the already installed or the precompiled self-downloaded version) use /data/web/node_modules as their location to install new packages to when using npm.

Troubleshooting

  • When using npm search, so much memory is used that on start and grow nodes, your shell will get killed and you’ll be automagically logged out of your hypernode due to our out of memory protection.

0