-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (26 loc) · 838 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const express = require("express");
const routes = require("./routes");
// import sequelize connection
const { Sequelize } = require("sequelize");
const sequelize = new Sequelize("ecommerce_db", "root", "password", {
host: "localhost",
dialect: "mysql",
});
const databaseConnectionTest = async () => {
try {
await sequelize.authenticate();
console.log("Connection has been established successfully.");
} catch (error) {
console.error("Unable to connect to the database:", error);
}
};
databaseConnectionTest();
const app = express();
const PORT = process.env.PORT || 3001;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(routes);
// sync sequelize models to the database, then turn on the server
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}!`);
});