Having this simple express app example:

var express = require('express')
var app = express()


app.use(express.static(__dirname+'/public'))


app.get('/', function(request,response) {

    response.send("This wont matter if we got an index.hml after all")
})

app.listen(2311, function() {

    console.log("app escuchando en Maricela DDMM")
})

And at /public I got an index.html.

When I get rid of such html the string in the send() method will be sent, received and rendered at browser.

What does actually happen with the response.send() string talking about the HTTP response, as the HTML is which is send and so rendered at browser?

有帮助吗?

解决方案

Express goes through the chain of middleware in the order in which it was added. You have added express.static as the first middleware, so it will be ran first.

In the event express.static cannot find a file, it calls next(), allowing the next bit of middleware to run. This is your handler set up with app.get('/' //..., which sends the data as you have told it to.

其他提示

I think it basically sets up the header information based on the parameter in send and then send the http response

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top