Skip to content
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
8 changes: 7 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
APP_PORT=5000
APP_PORT=3000
DB_HOST=localhost
DB_PORT=3306
DB_USER=REPLACE_WITH_YOUR_USERNAME
DB_PASSWORD=REPLACE_WITH_YOUR_PASSWORD
DB_NAME=REPLACE_BY_DB_NAME
JWT_SECRET=SECRET_KEY
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
.env

24 changes: 24 additions & 0 deletions database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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((result) => {
const movies = result[0];

console.log(movies);
})
.catch((err) => {
console.error(err);
});

module.exports = database;
42 changes: 22 additions & 20 deletions express_quests.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,51 +63,53 @@ CREATE TABLE users (
lastname varchar(255) NOT NULL,
email varchar(255) UNIQUE NOT NULL,
city varchar(255) DEFAULT NULL,
language varchar(255) DEFAULT NULL
language varchar(255) DEFAULT NULL,
hashedPassword varchar(255) NOT NULL
) ENGINE = InnoDB DEFAULT CHARSET = utf8;

INSERT INTO
users (firstname, lastname, email, city, language)
users (firstname, lastname, email, city, language, hashedPassword)
VALUES
(
'John',
'Doe',
'[email protected]',
'Paris',
'English'
),
(
'English',
"$argon2id$v=19$m=16,t=2,p=1$emVmZXpmemZlemVmZWR6ZXplZg$rqZkhxu5YbqCGHPNrjJZpQ"
),(
'Valeriy',
'Appius',
'valeriy.appius@example.com',
'valeriy.ppius@example.com',
'Moscow',
'Russian'
),
(
'Russian',
'$argon2id$v=19$m=16,t=2,p=1$emVmemVmemZlemZ6ZnpmZQ$eSetR6KPUNAGW+q+wDadcw'
),(
'Ralf',
'Geronimo',
'[email protected]',
'New York',
'Italian'
),
(
'Italian',
'$argon2id$v=19$m=16,t=2,p=1$emVmemVmemZlemZ6ZnpmZXphZGF6ZGQ$a0bg5DZB6H6v3jjQC81DXg'
),(
'Maria',
'Iskandar',
'[email protected]',
'New York',
'German'
),
(
'German',
'$argon2id$v=19$m=16,t=2,p=1$emVmemVmemZlenplZHpkZnpmemZlemFkYXpkZA$V1qAnJDyMuuWG7g9yoGYXA'
),(
'Jane',
'Doe',
'[email protected]',
'London',
'English'
),
(
'English',
'$argon2id$v=19$m=16,t=2,p=1$emVmemVmemZlenplZHpkZGZ6ZnpmZXphZGF6ZGQ$VCzq45PL9t8khtc44Kk5iw'
),(
'Johanna',
'Martino',
'[email protected]',
'Milan',
'Spanish'
);
'Spanish',
'$argon2id$v=19$m=16,t=2,p=1$emVmemVmemVmemZlenplZHpkZGZ6ZnpmZXphZGF6ZGQ$UKaGZ9hGFn/S5SBQDMe/Uw'
);
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const app = require("./src/app");
require("dotenv").config();

const port = 5000;
const port = process.env.APP_PORT;

app
.listen(port, () => {
Expand Down
Loading