Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

325
Views
Creating directory on root doesn't work via npm but does running node directly

app.js (root is not file owner)

var fs = require('fs');
fs.mkdirSync('/root/tmp');

package.json

{
  "scripts": {
    "app": "node app.js"
  }
}

When I run as root npm run app I got

> app
> node app.js

node:internal/fs/utils:344
    throw err;
    ^

Error: EACCES: permission denied, mkdir '/root/tmp'

But it works when I run just node app.js. Which setting/option of npm can help me run npm run app without errors?

Why npm run change user? How to force npm not to change user?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I can replicate the behavior you see on Linux if I run the commands in a shell I've run via sudo, like this: sudo bash. As in the question, npm run app fails but node app.js works.

The difference is that npm run app runs the executable JavaScript file npm-cli.js from the npm package, which looks like this:

#!/usr/bin/env node
require('../lib/cli.js')(process)

That tells us it's running node via env.

So I got to thinking: What user does that run as? So I added "who": "whoami" to package.json and did npm run who. The answer is: It runs as my normal account, not as root, even when I run that from a shell I've launched via sudo bash. My normal user account can't (of course) create subdirectories of root.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!