Reputation: 337
I'm using node
and express
in my app and web server for chrome
to serve web pages from a local folder over the network. I wanna direct the app to a page this way:
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
but it does not work and by using console.log()
, this path is shown:
D:\node\project10\index.html
as you see slashes are changed to backslashes. also tried to solve it this way:
path.join(__dirname.replace(/\\/g,"/") + '/index.html'))
Without path.join
the problem is solved but with having it the problem remains.
how to solve it?
Upvotes: 0
Views: 443
Reputation: 60
When you console.log() the path.join() it shows the dashes in the other direction because windows is working like that. In the browser the dashes are: '/' but in the windows are opposite. So the problem is not from the dashes.
Upvotes: 1