Search code examples
node.jsnpmnode-modulesnpm-install

How to install a global npm package using fnm (Fast Node Manager)?


My Problem
I have installed fnm (Fast Node Manager) from this github repo and it works all great except for installing global npm packages. For example, the well-known package nodemon is something I want installed globally and not im my node_modules project directory.

When installing the package globally there seems to be no problem: enter image description here

And when checking the global package list, nodemon seems to be there: enter image description here

But when running the command nodemon I get the following output: Image of my terminal output error

As also seen in the fnm repository documentation there is a need to run this piece of code eval "$(fnm env --use-on-cd)"; on load in order to get fnm to work properly and this is what I have done in the .bashrc file.

Note I am using windows 10, seems to be working on my mac laptop.

The Question
How can I have a global npm package installed for all or at least a single fnm node version? And what I mean by this, is that by running fnm use <NODE_VERION> you specify what node version to use as also seen in the repository documentation. I want to be able to run the nodemon command without it being installed in a project's node_modules directory.


Solution

  • You do not need to delete the multishells. The problem is the Git Bash path.

    Fix is here: https://github.com/Schniz/fnm/issues/390

    Put this in your .bashrc

    eval $(fnm env | sed 1d)
    export PATH=$(cygpath $FNM_MULTISHELL_PATH):$PATH
    
    if [[ -f .node-version || -f .nvmrc ]]; then
        fnm use
    fi