2

when i execute this single line script in linux as sudo i get an error, on my mac osx i don't.

var homedir =require('os').homedir();

error:

testhomedir.js:1
quire, module, __filename, __dirname) { var homedir = require('os').homedir();
                                                                    ^

TypeError: undefined is not a function

    at Object.<anonymous> (/home/marco/test/testhomedir.js:1:91)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

any idea's?

Marco St
  • 318
  • 2
  • 11
  • You're probably running an old version of Node on Linux (check with `node --version`). – robertklep Jul 01 '16 at 14:12
  • I'm using version 4.4.7 – Marco St Jul 01 '16 at 14:53
  • I'm running the same version on Linux, works fine. Are you sure that `sudo` is using the correct Node interpreter? Does `sudo node --version` give a different version? – robertklep Jul 01 '16 at 18:29
  • your right, sudo node --version gives me v0.12.4, i'm using nvm, thats probably why this happens. I found another stackoverflow post with the solution. – Marco St Jul 02 '16 at 10:05

1 Answers1

2

As Robert pointed out in the comment my sudo used another version of node than my regular user.

this stackoverflow post provided me with the answer to my problem

stop all the services that use node and issue the command

n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local

this copies the active used node version to the folder globally used.

Community
  • 1
  • 1
Marco St
  • 318
  • 2
  • 11