I have just started a new project using JS, NodeJS and SQL. I've done this loads of times before but for some reason when I try to test the backend endpoint it just keeps loading. The only thing that is different this time is that this the first time I'm implementing MySQL in my project. Here is my app.js file:
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const routes = require("./Routes/cardsRoutes");
const cors = require("cors");
app.use(bodyParser.json());
app.use(cors);
app.use(express.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.send("hi");
});
app.listen(8000, (req, res) => {
console.log("listening on 5000");
});
Here is my DB connection file:
const mysql = require("mysql");
var db = mysql.createConnection({
host: "localhost",
user: "root",
password: "Proctorate2506",
database: "srs",
});
db.connect((err) => {
if (err) {
console.log(err);
} else {
console.log("connected to db");
}
});
module.exports = db;
There isn't any error as well. I've tried in browser and Postman.
CodePudding user response:
Remplace
app.use(cors);
With
app.use(cors());
Everything else is fine