πŸ“.send Method

Now we'll learn how to send files to browser.

Send

app.get("/", (req,res) => {
    res.send("index.html",{
     username:"kubi"
    })
})

app.get("/login", (req,res) => {
    res.send("./dir/test.html")
})

Basicly that'll render the "index.html" in the index of the website. Nothing more to explain so basic isnt it?

<body>
   <h1>Welcome {= username =}</h1>
</body>

You can use the data that we set in javascript like "{= ur-javascript-variable =}".

Text

res.text("hello world")

Html

res.html(`
<!DOCTYPE html>
<html lang="en">
bla bla bla
`)

JSON

res.json({
test:"hi"
})

Download

res.download("test.zip","optional custom filename")

Last updated

Was this helpful?