-2
I’m new to Nodejs with Javascript, I got a ready example and I just want to add a condition in the body of the API type: If that value exists it shows the message in the API call via Insonmia or Postman and does not let include.
Código no VSCode
const express = require('express')
const server = express()
server.use(express.json())
const users = ["aa", "bb", "cc", "ddd"]
server.get('/users', (req, res) => {
return res.json(users)
})
server.post('/users', (req, res) => {
const { name } = req.body
users.push(name)
if (name == "aaaa") {
console.log("Registro existente.")
return res.json(users)
})
server.listen(3000)
Chamada API
{
"name": "aa"
}
via
This answers your question? Checking if value exists in an array via search field
– Rafael Tavares
This code does not compile.
– Danizavtz