Home > front end >  Having issues with app.post, results in Cannot Get /
Having issues with app.post, results in Cannot Get /

Time:11-20

I'm trying to create a sign-up page where users can enter information, however, I'm having issues with "app.post" properly working. This is what I have so far:

const express = require("express");

const db = require("./dbConnectExec.js")

const app = express();
app.use(express.json());

app.listen(5000, () => {
    console.log('App is running on port 5000');
});

app.get("/hi", (req,res) => {
    res.send("Hello world.");
});

app.get("/", (req,res) => {
    res.send("API is running.");
});

// app.post();
// app.put();

app.post("/customers", async(req, res) => {
    // res.send("/contacts called");
    // console.log("request body", req.body)

    let nameFirst = req.body.nameFirst;
    let nameLast = req.body.nameLast;
    let email = req.body.email;
    let password = req.body.password;

    let emailCheckQuery = `
    SELECT customer_email
    FROM Customer
    WHERE customer_email = '${email}'`;

    let existingUser = await db.executeQuery(emailCheckQuery);

    console.log("existing user", existingUser);

    if(existingUser[0]){return res.status(409).send("duplicate email")};

})

When I attempt to add a user through Postman, for example:

{"nameFirst": "Robert",
 "nameLast": "Redford",
 "email": "[email protected]",
 "password": "asdfasdf"}

I end up with "Cannot GET /customers"

CodePudding user response:

You have no GET handler for /customers only a POST handler

CodePudding user response:

In postman you can change your request from a GET to a POST request. Once you do it should hit this route endpoint.

note: "GET is used for viewing something, without changing it, while POST is used for changing something. For example, a search page should use GET to get data while a form that changes your password should use POST . Essentially GET is used to retrieve remote data, and POST is used to insert/update remote data."

  • Related