I am trying to make a PUT request, updating the users e-mail.
I am testing the endpoint with Postman.
I am pretty sure the mistake is in line 7, but I can’t seem to get it working.
My final goal, is updating the user email to whatever is put into a input field in HTML.
Is somebody able to spot what I am missing?
/src/routes/userRoutes.js
const express = require("express");
var Connection = require("tedious").Connection;
const sql = require("mssql");
const config = require("../../config.json");
var connection = new Connection(config);
const router = express.Router();
router.post("/updateUser", (req, res) => {
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
const email = req.body.email;
request.query(
`update dbo.[user]
set User_Email = '${email}'
where User_ID = 6`,
function (err, recordset) {
if (err) {
console.log(err);
} else {
console.log(`User has been updated!`);
res.json("Updated user");
}
}
);
});
});
app.js
const express = require('express')
const app = express();
const PORT = 3000;
const userRoutes = require('./src/routes/userRoutes')
const path = require('path')
app.use(express.static('./src/views'));
app.use(express.json())
app.use('/', userRoutes)
app.use('/createUser', userRoutes)
app.use('/updateUser', userRoutes)
app.use('/deleteUser', userRoutes)
//app.get('/updateProduct', (req,res) => {
// res.render(path.join(__dirname, '/src/views/updateProduct.html'))
//})
app.listen(PORT, () => {
console.log(`Server is listening on ${PORT}`);
})
POSTMAN output
Cannot PUT /updateUser