Reputation: 1461
My file structure is shown above, but I am unable to find the file with error: Undefined is not a function.
The app path is set, which I can get via a console.log: /Users/myname/Desktop/myproject/client
If I navigate to localhost:3000 for example, the page is rendered correctly. I can then click to navigate to localhost:3000/login and everything is still all good. But if I go directly to localhost:3000/login, i.e. the index page is never loaded, then this route: '/*' is hit and the undefined error occurs. No HTML is loaded.
I set the app path like so:
app.use(express.static(path.join(__dirname, '/client')));
app.set('appPath', path.join(__dirname, '/client'));
I am using Express: "~4.0.0"
Upvotes: 4
Views: 1619
Reputation: 243
You were close.
app.use(express.static(__dirname + '/client'));
Regards
Upvotes: 0
Reputation: 2260
http://expressjs.com/api.html#res.sendFile
res.sendFile() is supported from Express v4.8.0 onwards
Upvotes: 0
Reputation: 6200
Try to set the root for relative file path, this way:
app.set('base', __dirname);
and then:
app.use(express.static('client'));
Make sure not to include /client
twice, so you don't get something like .../client/client...
in your path.
Upvotes: 1