R
Railway7mo ago
JacobsV

How do I connect Webste <-> Server <-> Database❓

Github code for Main website in public and server.js https://github.com/Lanonymus/todowebsite/tree/main
GitHub
GitHub - Lanonymus/todowebsite
Contribute to Lanonymus/todowebsite development by creating an account on GitHub.
No description
No description
110 Replies
Percy
Percy7mo ago
Project ID: 413a7dad-c2ce-4187-8822-4c592f0b177c
Brody
Brody7mo ago
You are missing a package.json and a package-lock.json
JacobsV
JacobsVOP7mo ago
Alright I dowloanded them
JacobsV
JacobsVOP7mo ago
what do I put now in this box
No description
JacobsV
JacobsVOP7mo ago
No description
Brody
Brody7mo ago
your last github commit has you hardcoding the database credentials, please revert that commit. where are your package.json and package-lock.json files in github? nothing, it does not need to be filled if you correctly setup your project
JacobsV
JacobsVOP7mo ago
Dont I have to keep them as a secret variables?
Brody
Brody7mo ago
yes, so revert that commit
JacobsV
JacobsVOP7mo ago
OH I thought I hide them and also they are wrong ones lol
JacobsV
JacobsVOP7mo ago
where Do I revert
No description
Brody
Brody7mo ago
i think you should check out the github docs for that question
JacobsV
JacobsVOP7mo ago
oh well
Brody
Brody7mo ago
where are your package.json and package-lock.json files in github?
JacobsV
JacobsVOP7mo ago
Alright Changed Credentials and added packages-json how does it look now
Brody
Brody7mo ago
where is the package-lock.json?
JacobsV
JacobsVOP7mo ago
um Well I need to add it by using this command right in terminal ? :
npm install express
npm install express
Brody
Brody7mo ago
you would need to do that for all the deps your code uses
JacobsV
JacobsVOP7mo ago
I would have to dowloand every dependancy separately?
Brody
Brody7mo ago
you can specify multiple deps in a single command
JacobsV
JacobsVOP7mo ago
you mean npm install x y z etc? const express = require('express'); const session = require('express-session'); in this case express and the second one
Brody
Brody7mo ago
you use more than just those two packages, but you got the idea
JacobsV
JacobsVOP7mo ago
alright
JacobsV
JacobsVOP7mo ago
Is it supposed to be taking this long?
No description
Brody
Brody7mo ago
lol i dont know, do you have fast internet
JacobsV
JacobsVOP7mo ago
No description
JacobsV
JacobsVOP7mo ago
a decent I'd say
Brody
Brody7mo ago
oof 250ms under load
JacobsV
JacobsVOP7mo ago
No description
JacobsV
JacobsVOP7mo ago
yeah well ... It not bad right ?..
Brody
Brody7mo ago
faster than mine
JacobsV
JacobsVOP7mo ago
bro I think it paused
No description
JacobsV
JacobsVOP7mo ago
it ain't movin
Brody
Brody7mo ago
run it again
JacobsV
JacobsVOP7mo ago
alr lets see It may be caused of my grandpa using dowloanding some suspicious viruses online but that's another thread
Brody
Brody7mo ago
nope thats not another thread lol
JacobsV
JacobsVOP7mo ago
No description
JacobsV
JacobsVOP7mo ago
Bro I think my dog is eating the router cables or at least having them arleady straved
Brody
Brody7mo ago
let me know when you have a package.json and a package-lock.json file in your repo
JacobsV
JacobsVOP7mo ago
aLr
JacobsV
JacobsVOP7mo ago
Okay so I added those packages: https://github.com/Lanonymus/ToDoWebsite
GitHub
GitHub - Lanonymus/ToDoWebsite: My First official full-stack project.
My First official full-stack project. Contribute to Lanonymus/ToDoWebsite development by creating an account on GitHub.
JacobsV
JacobsVOP7mo ago
should be good now what do you think
JacobsV
JacobsVOP7mo ago
No description
Brody
Brody7mo ago
let me take a look those two files look good, you will now need to make a slight change to line 10 of server.js, for that change, please read this docs page - https://docs.railway.app/guides/fixing-common-errors
JacobsV
JacobsVOP7mo ago
node:internal/modules/cjs/loader:1080

throw err;

^

Error: Cannot find module 'express'

Require stack:

- /app/server.js

at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)

at Module._load (node:internal/modules/cjs/loader:922:27)

at Module.require (node:internal/modules/cjs/loader:1143:19)

at require (node:internal/modules/cjs/helpers:119:18)

at Object.<anonymous> (/app/server.js:2:17)

at Module._compile (node:internal/modules/cjs/loader:1256:14)

at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)

at Module.load (node:internal/modules/cjs/loader:1119:32)

at Module._load (node:internal/modules/cjs/loader:960:12)

at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12) {

code: 'MODULE_NOT_FOUND',

requireStack: [ '/app/server.js' ]

}

Node.js v18.18.2
node:internal/modules/cjs/loader:1080

throw err;

^

Error: Cannot find module 'express'

Require stack:

- /app/server.js

at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)

at Module._load (node:internal/modules/cjs/loader:922:27)

at Module.require (node:internal/modules/cjs/loader:1143:19)

at require (node:internal/modules/cjs/helpers:119:18)

at Object.<anonymous> (/app/server.js:2:17)

at Module._compile (node:internal/modules/cjs/loader:1256:14)

at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)

at Module.load (node:internal/modules/cjs/loader:1119:32)

at Module._load (node:internal/modules/cjs/loader:960:12)

at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12) {

code: 'MODULE_NOT_FOUND',

requireStack: [ '/app/server.js' ]

}

Node.js v18.18.2
It cannot find module express do I have to put node_modules in the github? @Brody
Brody
Brody7mo ago
no
JacobsV
JacobsVOP7mo ago
why railway cant find module express then
JacobsV
JacobsVOP7mo ago
No description
JacobsV
JacobsVOP7mo ago
it doesnt do anything
Brody
Brody7mo ago
please follow the instructions
JacobsV
JacobsVOP7mo ago
No description
JacobsV
JacobsVOP7mo ago
I did
Brody
Brody7mo ago
you didn't
JacobsV
JacobsVOP7mo ago
??? what am I supposed to do
Brody
Brody7mo ago
follow the 3 simple instructions please let me know when you have the build logs
JacobsV
JacobsVOP7mo ago
what are the
No description
JacobsV
JacobsVOP7mo ago
bro I am doing this first time Like what even is bookmarklet sounds like a book mouse from 2013 facebook 💀
JacobsV
JacobsVOP7mo ago
No description
JacobsV
JacobsVOP7mo ago
NaHHH tHAT's wild
Brody
Brody7mo ago
why would a YouTube search be helpful?
JacobsV
JacobsVOP7mo ago
No description
JacobsV
JacobsVOP7mo ago
I dont have the marklet bar 💀
Brody
Brody7mo ago
then enable it
JacobsV
JacobsVOP7mo ago
???
JacobsV
JacobsVOP7mo ago
No description
JacobsV
JacobsVOP7mo ago
Okay I did add it and run it but it says this
Brody
Brody7mo ago
do you have a deployment open?
JacobsV
JacobsVOP7mo ago
okay I did open it here are the logs
Brody
Brody7mo ago
I asked for the build logs
JacobsV
JacobsVOP7mo ago
they are empty
Brody
Brody7mo ago
do another deployment then
JacobsV
JacobsVOP7mo ago
here they are
Brody
Brody7mo ago
why does the deployment say 10 days ago are you deploying from the wrong GitHub repo
JacobsV
JacobsVOP7mo ago
No description
JacobsV
JacobsVOP7mo ago
well Oh wait I think I know hwy why am stupid xdd I didin't connect github
JacobsV
JacobsVOP7mo ago
Now it should be fine
Brody
Brody7mo ago
those are the exact same build logs you have previously sent
JacobsV
JacobsVOP7mo ago
no It has 6 more lines it a bit diffrent Now I get success
JacobsV
JacobsVOP7mo ago
No description
Brody
Brody7mo ago
🥳
JacobsV
JacobsVOP7mo ago
I mean kinnda succes xdd
JacobsV
JacobsVOP7mo ago
No description
Brody
Brody7mo ago
^
JacobsV
JacobsVOP7mo ago
app.use(express.static('public'));
app.use(express.json({limit: '1mb'}));
app.listen("0.0.0.0", () => console.log('Server Live at PORT 0.0.0.0'));
// Ustawienie domyślnego silnika szablonów
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.use(express.json({limit: '1mb'}));
app.listen("0.0.0.0", () => console.log('Server Live at PORT 0.0.0.0'));
// Ustawienie domyślnego silnika szablonów
app.set('view engine', 'ejs');
I am doing something wrong?
Brody
Brody7mo ago
yes you did, please read the docs page I linked
JacobsV
JacobsVOP7mo ago
aLright I think I fixed it
// Importuj moduły i ustaw serwer
const express = require('express');
const session = require('express-session');
const app = express();

app.use(express.static('public'));
app.use(express.json({limit: '1mb'}));

const port = process.env.PGPORT || 3000;

// Listen on `port` and 0.0.0.0
app.listen(port, "0.0.0.0", function () {
=> console.log('Server Live at PORT 0.0.0.0'))
});


// Ustawienie domyślnego silnika szablonów
app.set('view engine', 'ejs');


// Użyj sesji
app.use(session({
secret: 'secret-key',
resave: false,
saveUninitialized: false,
cookie: { maxAge: 1000 * 60 * 60 * 24 } // Sesja będzie ważna przez 1 dzień (zmień według potrzeb)
}));



// Teraz możesz użyć `res.locals.userId` w swoich routach, aby sprawdzić, czy użytkownik jest zalogowany.

// Przykład zabezpieczenia routy przed dostępem niezalogowanego użytkownika


// Przechowuj użytkowników w pamięci dla uproszczenia
const { Pool } = require('pg');
const pool = new Pool({
user: POSTGRES_USER,
host: PGHOST,
database: POSTGRES_DB,
password: PGPASSWORD,
port: PGPORT
});
// Importuj moduły i ustaw serwer
const express = require('express');
const session = require('express-session');
const app = express();

app.use(express.static('public'));
app.use(express.json({limit: '1mb'}));

const port = process.env.PGPORT || 3000;

// Listen on `port` and 0.0.0.0
app.listen(port, "0.0.0.0", function () {
=> console.log('Server Live at PORT 0.0.0.0'))
});


// Ustawienie domyślnego silnika szablonów
app.set('view engine', 'ejs');


// Użyj sesji
app.use(session({
secret: 'secret-key',
resave: false,
saveUninitialized: false,
cookie: { maxAge: 1000 * 60 * 60 * 24 } // Sesja będzie ważna przez 1 dzień (zmień według potrzeb)
}));



// Teraz możesz użyć `res.locals.userId` w swoich routach, aby sprawdzić, czy użytkownik jest zalogowany.

// Przykład zabezpieczenia routy przed dostępem niezalogowanego użytkownika


// Przechowuj użytkowników w pamięci dla uproszczenia
const { Pool } = require('pg');
const pool = new Pool({
user: POSTGRES_USER,
host: PGHOST,
database: POSTGRES_DB,
password: PGPASSWORD,
port: PGPORT
});
how does it look now
Brody
Brody7mo ago
still wrong, please do not skim read the docs page I linked
JacobsV
JacobsVOP7mo ago
bruuuu
JacobsV
JacobsVOP7mo ago
No description
JacobsV
JacobsVOP7mo ago
You meant this , Didin't you?
Brody
Brody7mo ago
nope, again do no skim read that docs page
JacobsV
JacobsVOP7mo ago
No description
JacobsV
JacobsVOP7mo ago
I dont have a PORT variable defined automaticly
JacobsV
JacobsVOP7mo ago
No description
Brody
Brody7mo ago
please do not skim read that
JacobsV
JacobsVOP7mo ago
???
Brody
Brody7mo ago
automatically injected is the key words here
JacobsV
JacobsVOP7mo ago
oh so you mean That I dont have to define it and I can just say PORT in the code
Brody
Brody7mo ago
the docs even tell you not to define it in the future please read documentation more carefully
JacobsV
JacobsVOP7mo ago
okay I think I corrected all those goofy errors lets see if it works Oh MA gAT IT WORKING yOOOOOOOOooooooooooooooooooooooooooooOOOOOOOOOOO
JacobsV
JacobsVOP7mo ago
No Freaking way https://todowebsite-production.up.railway.app/index.html @Brody can u test it out ? and give it Rate ⭐ ??
Brody
Brody7mo ago
1/10
JacobsV
JacobsVOP7mo ago
that's better then 0
Want results from more Discord servers?
Add your server