I wanna add DNS and IP address provided by render in my backend cause i m getting error in the connection but i m not able to find the DNS and IP adress.
can anyone help plss.
Hi Asha,
It might be worth explaining what you’re trying to accomplish here,
Regards,
John B
Render Support, UTC
Hello sir,
So i have an application using react and for the backend i have used MYSQL and express.
require("dotenv").config();
const express = require("express");
const mysql = require("mysql");
const cors = require("cors");
const app = express();
const port = 10000;
const db = mysql.createConnection({
host: "localhost",
user: "root",
password: "password",
database: "expense",
});
// Example of handling connection errors
db.connect(function (err) {
if (err) {
console.error("Error connecting to database:", err);
return;
}
console.log("Connected to database!");
});
app.use(express.json());
app.use(cors());
app.get("/", (req, res) => res.json("Hi from backend"));
app.post("/expenses", (req, res) => {
const q = "INSERT INTO expenses (`text`, `amount`, `type`) VALUES (?)";
const values = [req.body.text, req.body.amount, req.body.type];
db.query(q, [values], (err, data) => {
if (err) return res.json(err);
return res.json("expense created successfully");
});
});
app.delete("/expenses/:id", (req, res) => {
const expenseId = req.params.id;
// const q = "DELETE FROM expenses WHERE id = ?";
db.query(q, [expenseId], (err, data) => {
if (err) return res.json(err);
return res.json("expense deleted successfully");
});
});
app.put("/expenses/:id", (req, res) => {
const expenseId = req.params.id;
const q =
"UPDATE expenses SET `text`=? , `amount`= ? , `type` = ? WHERE id = ?";
const values = [req.body.text, req.body.amount, req.body.type];
db.query(q, [...values, expenseId], (err, data) => {
if (err) return res.json(err);
return res.json("expense updated successfully");
});
});
app.get("/expenses", (req, res) => {
const q = "SELECT * FROM expenses";
db.query(q, (err, data) => {
if (err) return res.json(err);
console.log(data);
if (data) return res.json(data);
});
});
app.listen(process.env.PORT || port, (req, res) => {
console.log(`connected to backend port is ${port}`);
});
This is the code of my backend file.
When i try to upload this file on the backend on the index route i m getting my string i.e " hi from backend"
but whenever i try to use /expenses route i m getting this error {“code”:“PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR”,“fatal”:false}
please help.
Ok, so where are you running the mySQL service?
John B
Render Support, UTC
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.