Bits and Bytes

Installing global npm packages without sudo

If you want to avoid that you have to use sudo for installing global npm packages here is how you can change the path where the node modules are installed to a directory that does not need root rights.

npm config set prefix '~/.npm-packages'
export PATH="$PATH:$HOME/.npm-packages/bin"

After this npm install -g should work just fine with normal user rights.

Ubuntu 14.04 npm node.js
July 3, 2015

Making sass image-url work

To ensure correct paths to your assets (e.g. pictures) in Rails it is recommended to use the image-url helper function. Unfortunately I found myself confronted with the problem that this worked fine my production environment on Heroku but not in development. I fixed the problem by deleting everything inside the assert cache folder. You can use this command when you are in the root directory of your Rails project.

rm -r ./tmp/assets/cache/*
Rails 4 sass/scss
July 16, 2015

Updating node.js using n

I had troubles updating node.js on my Ubuntu 14.04 system using the provided n package. Here the commands that made it work for me.

sudo npm install -g npm@latest; sudo npm install -g n@latest;
sudo -E env "PATH=$PATH" n latest
Ubuntu 14.04 node.js n
November 20, 2015

Overwriting node config values

If you are using the node-configmodule to handle your configuration you might get in trouble when running tests. Either you want to run tests for different config values or you want to set some value that would usually be set via a local config which does not exist in the testing environment.

As an example let's assume a config file with this content:

server:
    ip: 10.10.10.10
    port: 8000

To overwrite this you need to allow mutations on the config options. This is either done by including ALLOW_CONFIG_MUTATIONS = 1 in your npm test script or by putting this at the very top of the test file that is first requiring the config module:

process.env['ALLOW_CONFIG_MUTATIONS'] = 1;

After that server.ip can be overwritten with like this:

config.get('server')['ip'] = 'localhost';
node node-config testing
August 1, 2016
comments powered by Disqus