TypeError: res.send is not a function
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);
});
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.
You named the fetch called res, so you need to change the variable, here is correct code: