added example .env

This commit is contained in:
slawk0
2024-08-26 20:39:04 +02:00
parent 135b8449ea
commit 323d4f0661
3 changed files with 33 additions and 18 deletions

7
.env Normal file
View File

@@ -0,0 +1,7 @@
PG_HOST=db
PG_PORT=5432
PG_USER=postgres
PG_PASSWORD=changeme
PG_DATABASE=webchat
SESSION_SECRET=changeme
JWT_SECRET=changeme

3
.gitignore vendored
View File

@@ -1,4 +1,3 @@
node_modules/
.idea
package-lock.json
.env
package-lock.json

View File

@@ -15,24 +15,33 @@ db.connect()
.catch((err) => console.log('Error on connecting to database: ', err));
async function createTables() {
await db.query(`
CREATE TABLE IF NOT EXISTS accounts (
id SERIAL PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL
)
`);
try {
// Create accounts table
await db.query(`
CREATE TABLE IF NOT EXISTS accounts (
id SERIAL PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL
)
`);
// Create messages table
await db.query(`
CREATE TABLE IF NOT EXISTS messages (
id SERIAL PRIMARY KEY,
content TEXT NOT NULL,
username VARCHAR(50) NOT NULL,
recipient VARCHAR(255) NOT NULL
)
`);
// Create messages table
await db.query(`
CREATE TABLE IF NOT EXISTS messages (
id SERIAL PRIMARY KEY,
content TEXT NOT NULL,
username VARCHAR(50) NOT NULL,
recipient VARCHAR(255) NOT NULL
)
`);
console.log('Tables created successfully');
} catch (err) {
console.error('Error creating tables:', err);
throw err;
}
}
createTables()
.catch((err) => {
console.error('Error creating tables:', err);