Skip to content
← Back to Community
TypeError: res.send is not a function
Profile icon
Axel1672

const express = require("express")
const app = new express()
const fetch = require("node-fetch")
const groupId = process.env.groupId

app.get("/groupmembers/:id", (req, res) => {
var Key = req.params.id

if (Key === process.env.key) {

fetch('https://groups.rprxy.xyz/v1/groups/' + groupId).then(res => res.json()).then(res => { const groupMembers = res.memberCount res.send(groupMembers); })

}
});

const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});

Voters
Profile icon
Axel1672
Comments
hotnewtop
Profile icon
Coder100

You named the fetch called res, so you need to change the variable, here is correct code:

const express = require("express") const app = new express() const fetch = require("node-fetch") const groupId = process.env.groupId app.get("/groupmembers/:id", (req, res) => { var Key = req.params.id if (Key === process.env.key) { fetch('https://groups.rprxy.xyz/v1/groups/' + groupId).then(r => r.json()).then(r => { const groupMembers = r.memberCount; res.send(groupMembers); }) } }); const listener = app.listen(process.env.PORT, () => { console.log("Your app is listening on port " + listener.address().port); });
Profile icon
[deleted]

You are trying to use an environment variable that does not exist. You can see the current ones using console.log(process.env). To add a new one to the .env file you need to use the feature to the left of the file list that is shaped like a padlock. It looks like you will need to create one for groupId. Once you have created a variable sample code will appear that shows you how to access the variable in your code.

Also, do you need to have .env variables? Can't you just hard code something like groupId in the main scope of your program?

All the best.