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);
Tryout this way
app.use(express.static(__dirname + '/public'));
i mean use __dirname for get from main root path .
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.