Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express 01.2 #119

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.env
22 changes: 22 additions & 0 deletions database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require("dotenv").config();

const mysql = require("mysql2/promise");

const database = mysql.createPool({
host: process.env.DB_HOST, // address of the server
port: process.env.DB_PORT, // port of the DB server (mysql), not to be confused with the APP_PORT !
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
});

database
.query("select * from movies")
.then(([movies]) => {
console.log(movies);
})
.catch((err) => {
console.error(err);
});

module.exports = database;
13 changes: 6 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
require("dotenv").config();
const app = require("./src/app");

const port = 5000;

app
.listen(port, () => {
console.log(`Server is listening on ${port}`);
})
.on("error", (err) => {
console.error("Error:", err.message);
});
app.listen(port, () => {
console.log(`Server is listening on ${port}`);
}).on("error", (err) => {
console.error("Error:", err.message);
});
195 changes: 193 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
},
"homepage": "https://github.com/WildCodeSchool/Express-Quests#readme",
"dependencies": {
"express": "^4.18.2"
"dotenv": "^16.3.1",
"express": "^4.18.2",
"mysql2": "^3.6.5"
},
"devDependencies": {
"jest": "^29.7.0",
"nodemon": "^2.0.19",
"nodemon": "^2.0.22",
"supertest": "^6.3.3"
}
}
5 changes: 5 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ const movieControllers = require("./controllers/movieControllers");
app.get("/api/movies", movieControllers.getMovies);
app.get("/api/movies/:id", movieControllers.getMovieById);

const userControllers = require("./controllers/userControllers");

app.get("/api/users", userControllers.getUsers);
app.get("/api/users/:id", userControllers.getUsersById);

module.exports = app;
Loading