1
votes

any help or suggestion will be appreciated.

C:\Program Files\nodejs\node_global\node_modules\express\node_modules\serve-static\index.js:40 throw new TypeError('root path required') ^

TypeError: root path required at Function.serveStatic [as static] (C:\Program Files\nodejs\node_global\node_modules\express\node_modules\serve-static\index.js:40:11) at Object. (C:\Users\joe\Downloads\fine\nodejs.js:40:40) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16) at bootstrap_node.js:612:3`

the only static path I am using for are.

app.use(express.static(publicDir));
app.use("/node_modules", express.static(nodeModulesDir));

app.post("/uploads", onUpload);
app.delete("/uploads/:uuid", onDeleteFile);
1
Because you didn't set root path?marekful
Was my answer useful?Anshuman Jaiswal

1 Answers

5
votes

you are passing variable nodeModulesDir, it must be set to node_modules or you can directly pass string as:

Approach 1:

var nodeModulesDir = 'node_modules';
app.use("/node_modules", express.static(nodeModulesDir));

Approach 2:

app.use("/node_modules", express.static('node_modules'));