Search code examples
node.jsnpmdeb

npm don't install module every time


The problem is that npm install rebuilds and reinstalls a module every time, even if the module is already installed.

I've made a .deb package that among other things installs a nodejs app.

But that app needs express and sqlite3 modules. I install them in the postinst of .deb:

npm install -g express sqlite3

And never remove it.

So, during .deb installation sqlite3 js module is recompiled and reinstalled every time. That takes forever on Raspberry.

How to make it work correctly?


Solution

  • For now I'm going with:

    nodejs_modules="express sqlite3"
    nodejs_modules_installed="$(npm list -g --depth=0)"
    
    for m in $nodejs_modules; do
        if ! echo "$nodejs_modules_installed" | grep -q "\\s$m"@; then
            npm install -g "$m"
        else
            npm update -g "$m"
        fi
    done