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

1.2K
Views
Node TypeError: root path required

I am trying to setup a simple node/express server and I receive the following error

TypeError: root path required

I would like to know how to fix this error. Thanks


var nodeModulesDir = process.env.NODE_MODULES_DIR,

app.use(express.static(publicDir));
app.use("/node_modules", express.static(nodeModulesDir)); // ERROR AT THIS LINE
app.post("/uploads", onUpload);
app.delete("/uploads/:uuid", onDeleteFile);
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Tryout this way

app.use(express.static(__dirname + '/public'));

i mean use __dirname for get from main root path .

about 4 years ago · Santiago Trujillo Report

0

modify .bash_profile add export NODE_MODULES_DIR=GGGGGGGGGGG

enter image description here

BTW, Don't forget restart the server!

about 4 years ago · Santiago Trujillo Report

0

TL;DR: check your publicDir or nodeModulesDir variables that you are passing.

Express uses the module serve-static.

so the error comes from:

function serveStatic (root, options) {
  if (!root) {
    throw new TypeError('root path required')
  }
   ...
}

serveStatic(root, options)

Create a new middleware function to serve files from within a given root directory. The file to serve will be determined by combining req.url with the provided root directory. When a file is not found, instead of sending a 404 response, this module will instead call next() to move on to the next middleware, allowing for stacking and fall-backs.

about 4 years ago · Santiago Trujillo 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!