How to reply to query request sent by user in node js
app.post(“/register”, (req, res) => { let id = req.body.id; let name = req.body.name; let email = req.body.email; cmd = “INSERT INTO emp VALUES(?, ?, ?)”; conn.connect((err) => { if (err) throw err; let con = conn.query(cmd, [id, name, email], (err, res) => { if (err) throw err; console.log(res); }); }); }); I have a post […]
Error when trying to access property from MongoDB
When I console.log(entry)
, it outputs:
Need Help in NODEJS
console.log(entry) gives ({
_id: new ObjectId(‘669c834c6e93a548837c6572’),
shortId: ‘NpreYDMaH’,
redirectURL: ‘amazon.in’,
visitHistory: [],
createdAt: 2024-07-21T03:41:00.236Z,
updatedAt: 2024-07-21T03:41:00.236Z,
__v: 0
}
null) however when i use res.redirect(entry.redirectURL) it says can’t read properties of null(reading redirectURL) , why it happens when there is redirectURL in entry
Not able to add the data in database :postman error:Cannot GET /api/v1/createTodo
const express = require(“express”); const app = express(); //load config from env file require(“dotenv”).config(); const PORT = process.env.PORT || 4000; //middleware to parse json request body app.use(express.json()); //import routes for TODO API const todoRoutes = require(“./routes/todos”); //mount the todo API routes app.use(“/api/v1”, todoRoutes); //start server app.listen(PORT, () => { console.log(`Server started successfully at ${PORT}`); }) […]
Problem in generating cookies from frontend side
export const login = async (req, res) => { const { username, password } = req.body; try { // CHECK IF THE USER EXISTS const user = await prisma.user.findUnique({ where: { username }, }); if (!user) return res.status(400).json({ message: “User Not Found!” }); // CHECK IF THE PASSWORD IS CORRECT const isPasswordValid = await bcrypt.compare(password, […]