Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem with the node_module-path. Can someone let me know what I'm doing wrong?


exec sudo -u www-data /usr/bin/node /etc/node/app.js

gives me

Error: Cannot find module 'connect'

I have this config (/etc/init/applicationserver.conf):

start on started mountall
stop on shutdown

respawn limit 99 5

    export HOME="/"
    export NODE_PATH="/usr/lib/node_modules"

    exec sudo -u www-data /usr/bin/node /etc/node/app.js >> /var/log/applicationserver.log 2>&1
end script

post-start script

end script

It seems like it can't find the modules installed. I've verified that connect is under /usr/lib/node_modules and if I export NODE_PATH from root or my account it works fine.

share|improve this question
up vote 1 down vote accepted

Hmm, not the best way to be starting something in general. A wrapper script with the correct ownership could do the same work without sudo.

You're problem is in the use of sudo, regardless of the context as an upstart job. The environmental vars you're defining aren't being passed on. Add the '-E' switch to sudo to correct this.

If you used a wrapper owned by www-data to start that process you wouldn't have this problem because you wouldn't have needed sudo. There are lots of example jobs that create vars and pass them on to the new child process. It's a basic property of fork/clone.

share|improve this answer
I'm all ears on if there is a better way to start it. Any suggestions? I'm quite the noob on these things. – Asken Nov 20 '11 at 17:10
Btw, the -E made it work. When thinking of it, it seems logic that the env vars don't follow by default. – Asken Nov 20 '11 at 17:20
How about this? cat #!/bin/sh /usr/bin/node /etc/node/app.js >> /var/log/applicationserver.log 2>&1 chown www-data:root and run that instead? – ppetraki Nov 20 '11 at 18:42
I'll do that. Just a final question. why www-data:root and not www-data:www-data or it doesn't matter? – Asken Nov 21 '11 at 9:25
Just not leaving it to chance. This is basic Unix system administration and there is plenty of documentation on the subject. – ppetraki Nov 21 '11 at 14:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.