require('os').homedir() error on linux

113 views
Skip to first unread message

Marco Stolle

unread,
Jul 1, 2016, 9:35:18 AM7/1/16
to nodejs
Hello,

i'm testing a library where i have to run the script with sudo, thats when i get an error on the line

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

(i also get this error in a file with only this line, it's unrelated to the library)

this results in 

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



on mac i don't have this problem on linux i do


any ideas?

Witold Szczerba

unread,
Jul 1, 2016, 11:24:11 AM7/1/16
to nod...@googlegroups.com
Just checked on my Ubuntu 14.04:

[ witoldsz@svp:~ ]$ sudo su -
root@svp:~# /opt/node/bin/node --version
v4.1.1
root@svp:~# /opt/node/bin/node
> require('os').homedir()
'/root'

Seems to be working just fine.
> --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nodejs+un...@googlegroups.com.
> To post to this group, send email to nod...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/ede2e5ab-c43c-4292-966b-12451c3c7f8e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

Ben Noordhuis

unread,
Jul 1, 2016, 11:24:11 AM7/1/16
to nod...@googlegroups.com
Your Mac has a version of node.js installed that has os.homedir(),
your Linux machine does not.

Going by the line numbers in the stack trace, it's node.js v0.12.
os.homedir() didn't appear until io.js v2.3.0.
Reply all
Reply to author
Forward
0 new messages