The site works on localhost and is connected to the database in Postgres (the database I opened)
And now I can’t upload the site to Heroku because of problems related to it I guess. Does anyone have any way to help?
This is the server.js file that contains the code with queries to my table in postgress but with an attempt to change to DATABASE_URL
So you’re a bit stuck in the middle and at a loss.
Thank you! 🙂
const { Client } = require('pg');
const express = require('express');
const body Parser = require('body-parser');
const app = express();
const port = process.env.PORT || 3000;
const db = new Client({
connection String: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false
}
});
db.connect();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
app.get("/", async (req, res) => {
try {
const result = await db.query("SELECT * FROM sku_tracking ORDER BY id ASC");
const sku_tracking = result.rows;
res.render("index.ejs", {
listsku: sku_tracking,
});
} catch (err) {
console.log(err);
res.status(500).send("Internal Server Error");
}
});
app.post("/add", async (req, res) => {
const sku_code = req.body.newSku;
const date_added = new Date();
try {
await db.query("INSERT INTO sku_tracking (sku_code, date_added) VALUES ($1, $2)", [sku_code,date_added]);
res.redirect("/");
} catch (err) {
console.log(err);
res.status(500).send("Internal Server Error");
}
});
app.post("/delete", async (req, res) => {
const id = req.body.deleteskuId;
try {
await db.query("DELETE FROM sku_tracking WHERE id = $1", [id]);
res.redirect("/");
} catch (err) {
console.log(err);
res.status(500).send("Internal Server Error");
}
});
app.post("/updateDateOrder", async (req, res) => {
const ordered = req.body.dateOrderChecked;
const id = req.body.updatedskuId;
const order_date = new Date();
try {
await db.query("UPDATE sku_tracking SET ordered = $1, order_date = $2 WHERE id = $3", [ordered,order_date, id,]);
res.redirect("/");
} catch (err) {
console.log(err);
res.status(500).send("Internal Server Error");
}
});
app.post("/updateDateArrival", async (req, res) => {
const arrived = req.body.dateArrivalChecked;
const id = req.body.updatedskuId2;
const arrival_date = new Date();
try {
await db.query("UPDATE sku_tracking SET arrived = $1, arrival_date = $2 WHERE id = $3", [arrived,arrival_date, id,]);
res.redirect("/");
} catch (err) {
console.log(err);
res.status(500).send("Internal Server Error");
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
Trying to follow the commands to upload the site to HEROKU, but because there is a problem with my DATABASE, and I don’t know how to make the adjustments, I can’t open the application
open app —> Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs –tail
Tomer Efrat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.