I\'m trying the following code but it\'s giving me an error, \"res.send is not a function\". Please help me.
Here\'s the code:
var http = require(\'
Swap req & res : function(req, res)
According to the API reference, the first param always contain request req
, then response res
.
So change first param res
to req
:
app.get('/', function(req, res) {
res.send("Rendering file")
}
It should fix it.
You can change your mind in some cases and could be write like this. note: by default, when you run node server on your local machine. Your host will always be localhost:"your desire port" Thank you!
const express = require("express")
const app = express();
const port = 8888;
// for redering hello you don't need to require fs
const fs = require("fs")
app.get ('/', (req, res) => {
res.send("hello world")
})
app.listen(port, () => console.log(`Listening on ${port}`))
you should use req argument first and res as the second argument this will work without any issue
app.get('/', function(req, res) {
res.send("Rendering file")
}
You've got the res
and req
parameters the wrong way around.
app.get('/', function(res, req)
should be
app.get('/', function(req, res)
Source: API docs.