Reputation: 147
I use this line
express.static(path.join(__dirname, 'public')));
Does it pass to the client post or get request?
Because if i use
express.get("/",function(res,req){
res.send(dataWirhDb);
}
There is no data on the client. If I use post request, I get data from the server.
If I use without
express.static(path.join(__dirname, 'public')))
and send to the client using get request, data is received on the client.
why does this happen?
Upvotes: 2
Views: 260
Reputation: 38543
No, express.static
does not execute any requests. It's just a setup function that tells express that it needs to serve static files, and where to find them.
In this case the location is path.join(__dirname, 'public')
, which means the public
folder within your application directory.
The static files (like css, images, index.html etc.) are served automatically without the need of setting up routes for them. "Served" in this context means that the server sends the file back as a response to a GET request by the client, asking for that file.
Upvotes: 1