The simplest way to install Node.js is by QNAP App center. However the package from app center does not work correctly and in addition the package install the outdate version of Node.js.

When I installed Node.js by App Center, I was non able to run npm command, it always return the error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
module.js:340
    throw err;
          ^
Error: Cannot find module 'npmlog'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at /share/MD0_DATA/.qpkg/nodejs/node/bin/npm:18:11
    at Object.<anonymous> (/share/MD0_DATA/.qpkg/nodejs/node/bin/npm:86:3)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

After several hours of looking in internet and struggling with installation, I found a way that worked for me:

1. Install the Node.js by QNAP App Center
2. Open SSH to you QNAP and login by admin user
For Mac, open terminal and type: ssh {QNAP IP} -l admin
For Windows you can use PuTTY tool from the site: Download page
3. Run the commands:

1
2
3
4
5
6
cd /share/MD0_DATA/.qpkg/nodejs
wget http://nodejs.org/dist/v0.10.32/node-v0.10.32-linux-x86.tar.gz
tar zxf node-v0.10.32-linux-x86.tar.gz
mv node node-v0.8.22
ln -s node-v0.10.32-linux-x86 node
npm version

Script explanation:
Line:2 – download the latest version of Node.js, you can change version “v0.10.32” in the line to any version of Node.js from their site: Node.js
Line:3 – uncompress the downloaded file, put attention on version in case you changed it.
Line:4 – move old files to tmp directory.
Line:5 – create link with name “node” to the new version of Node.js, you should put attention on version in name, in case you changed it.
Line:6 – the command will display current Node.js version. In my case the output was:

1
2
3
4
5
6
7
8
9
{ http_parser: '1.0',
  node: '0.10.32',
  v8: '3.14.5.9',
  ares: '1.9.0-DEV',
  uv: '0.10.28',
  zlib: '1.2.3',
  modules: '11',
  openssl: '1.0.1i',
  npm: '1.4.28' }

4. If you try to run any complicated command like “npm install -g grunt-cli” now, you will get error:

1
2
3
4
5
6
7
8
Error: setuid user id does not exist
    at /share/MD0_DATA/.qpkg/nodejs/node-v0.10.32-linux-x86/lib/node_modules/npm/node_modules/uid-number/uid-number.js:44:16
    at ChildProcess.exithandler (child_process.js:646:7)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:756:16)
    at Socket.<anonymous> (child_process.js:969:11)
    at Socket.emit (events.js:95:17)
    at Pipe.close (net.js:465:12)

The problem is QNAP lacks couple of system users available on Linux systems and does not support get or set user-id. So we should modify Node.js source code.
Run the command (put attention on the version of Node.js):

1
vi /share/MD0_DATA/.qpkg/nodejs/node-v0.10.32-linux-x86/lib/node_modules/npm/node_modules/uid-number/uid-number.js

The command will open “uid-number.js” file in vi editor.

You should change line (you can enter to edit mode by pressing “i”):
,uidSupport = process.getuid && process.setuid
to
,uidSupport = false
on Line 11 in the file.

Save the file by pressing “Esc” -> “Shift” + “:” -> “w” -> “q”

This is it,
Enjoy Node.js latest version.

21 Thoughts on “QNAP – Node.js installation

  1. inktomat on November 8, 2014 at 4:58 pm said:

    Thank You! This helped tremendously.

  2. THANKS a lot Yura!

  3. Hi,

    this only works on x86 qnap machines, right? Is the a precompiled version for arm too?

    BR,
    Lars

  4. Hi Panshin

    Good morning, I’m Nelson , from Taiwan

    I have same question about install mongo DB on QNAP and I follow your guide to solved my.

    But did you ever been face every time I reboot my QNAP nas , need manually start mongo db with ssh, the command like is

    “mongod –dbpath=/share/HDA_DATA/.qpkq/mongo/data/db”

    I’m looking for the answer , unfortunately no one face same problem with me.

    can you tech me how can fix this.

    Thank you

    Nelson

    sorry, my English is very poor.

    • Hi Nelson,

      I am sorry, but I never created scripts to run it after reboot. However there are lot of examples of such scripts. Please google it.

  5. Johannes on January 2, 2015 at 5:08 pm said:

    Thanks for your detailed description. Unfortunately I got a different error message:

    /bin/npm: line 2: /bin/node: cannot execute binary file
    /bin/npm: line 2: /bin/node: Success

    I’ll come back when/if I’m able to make sense of that.

    • Johannes on January 4, 2015 at 10:23 am said:

      Ok, I did a bit of research and these are the results.

      # cd /share/HDA_DATA/.qpkg/nodejs
      # type npm
      npm is hashed (/bin/npm)
      # ls -l /bin |grep npm
      lrwxrwxrwx 1 admin administ 41 Jan 2 18:05 npm -> /share/HDA_DATA/.qpkg/nodejs/node/bin/npm*
      # ls -l node/bin |grep npm
      lrwxrwxrwx 1 admin administ 38 Jan 4 11:06 npm -> ../lib/node_modules/npm/bin/npm-cli.js*

      So `npm` links to `node/lib/node_modules/npm/bin/npm-cli.js`

      This is an executable shell script and starts with:

      # head node/lib/node_modules/npm/bin/npm-cli.js
      #!/bin/sh
      // 2>/dev/null; exec “`dirname “$0″`/node” “$0” “$@”

      If I understand this correctly, it tries to call `node/lib/node_modules/npm/bin/node` with `npm-cli.js` and its arguments as parameter.
      But there is no `node/lib/node_modules/npm/bin/node`.

      Any ideas?

  6. Hi,

    Struggling with this issue as well. I followed your steps which looks very straight forward. But it keeps telling me “-sh: npm: command not found”. While there was no error with downloading and uncompressing the .tar file. Do you`ve got any idea why this is?

  7. Michele on April 5, 2015 at 2:21 pm said:

    Hello, i’m trying to install node.js on my qnap.
    I’ve installed it from App center, but when I use putty for goes into
    cd /share/MD0_DATA/.qpkg/nodejs

    I can’t find the Dir MD0_DATA, i’ve only HDA_DATA, HDB_DATA etc.

    Can you help me???

    • Hmm, on my machine I have MD0_DATA, however as I can see from other comments, on some machines the .qpkg folder is on HDA_DATA.

  8. Michele on April 6, 2015 at 11:24 pm said:

    Hello, i’ve found the directory node in a subdir of HDA_DATA, i’ve tried all without error but when I type npm version i’ve a NPM error, it says me “no such file or directory”. What I’ve to do???

  9. Pingback: Install the most recent node.js version on your QNAP | node & co

  10. Hi Yura,

    Thanks so much for this. I get as far as line 5 – I’m using the most recent version, which is node-v4.2.2-linux-x86.tar.gz. But when I try

    npm version

    I get

    -sh: npm: command not found

    the symbolic link from the node folder is pointing at node-v4.2.2-linux-x86/ as it should. Any ideas?

  11. Andy Badera on July 5, 2016 at 1:10 am said:

    Thanks, still helpful currently.

  12. THANK YOU! You are so awesome! I love how you explain every line. I don’t use Linux enough, but I am tech savy and so all I need is a little explanation to help me understand what’s going on with all the commands you have me type. FYI my QNAP did not have a MD0 but I had an HDA so I used that. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation