trying to connect to postgres w/ next.js

As it says on the tin. The error message is:
context: 8e856b9da996ac0dcfcb8d39a0770302

Nixpacks build failed





╔════════ Nixpacks v1.20.0 ═══════╗

║ setup │ nodejs_18, npm-9_x ║

║─────────────────────────────────║

║ install │ npm ci ║

║─────────────────────────────────║

║ start │ ║

╚═════════════════════════════════╝



Error: No start command could be found
context: 8e856b9da996ac0dcfcb8d39a0770302

Nixpacks build failed





╔════════ Nixpacks v1.20.0 ═══════╗

║ setup │ nodejs_18, npm-9_x ║

║─────────────────────────────────║

║ install │ npm ci ║

║─────────────────────────────────║

║ start │ ║

╚═════════════════════════════════╝



Error: No start command could be found
I am totally new to Railway and deploying websites more generally and I have no idea where to even start, although StackOverflow suggests I could try changing my Railway settings to add the custom build command CI=false npm run build but this, too, did not work.
351 Replies
Percy
Percy11mo ago
Project ID: 551bf6a9-effd-4096-953e-ef1e8bd61cb5
Nephew Jonathan
Nephew JonathanOP11mo ago
My project ID is 551bf6a9-effd-4096-953e-ef1e8bd61cb5. I presume the issue is maybe in package.json or package-lock.json but I'm unsure where to start.
Medim
Medim11mo ago
Hey! Are those two included in the repo?
Nephew Jonathan
Nephew JonathanOP11mo ago
They should be!
Medim
Medim11mo ago
Can you show your package.json?
Fragly
Fragly11mo ago
could you send your package.json?
Nephew Jonathan
Nephew JonathanOP11mo ago
Yes, they are.
Fragly
Fragly11mo ago
🧠 ---🧠
Fragly
Fragly11mo ago
you need to specify a start command
Nephew Jonathan
Nephew JonathanOP11mo ago
Right. Right now that's, uh. oh I see oh I see so build command and start command are a bit different so what should I specify as the start command
Medim
Medim11mo ago
Yes! is it an API? JS or TS?
Nephew Jonathan
Nephew JonathanOP11mo ago
It's all JS/HTML. Uh...I don't think it's an API really. It's--here lemme show you the site as it exists
Medim
Medim11mo ago
What do u use to run it locally?
Nephew Jonathan
Nephew JonathanOP11mo ago
https://eliotweb-production.up.railway.app/index.html I use a Python mini-server. The text browser works fine, but I'm now working on an admin site to update JSONs (or maybe the database, which I have yet to implement, but which is why I installed mysql) when editing text files. (The website is for viewing and comparing the texts of two editions of a 17th-century Bible translation in a language that isn't spoken anymore, so typos when copying are inevitable, so I need to be able to update the JSONs/(database entries) it's pulling from when I edit the text files...) (so the idea behind the admin page is: select a book--e.g. suppose I just proofread Exodus--and it re-processes the updated text into the relevant JSON entries like the concordance and the verse JSON that contains the compared verses and stuff like that) (Previously I had been struggling to figure out how the hell to get it to require('fs') from node_modules, which it really didn't want to do. I get that it's trying to firewall itself from the user's system but I want to be able to change server-side files! (I still cannot get fs working but that's a different problem brb--shower
Adam
Adam11mo ago
Would it be possible for you to share your repo? Sounds like you have an unconventional setup Railway’s Nixpacks builder is fantastic at automatically detecting languages and assigning build commands, but only if the project is structured similar to a standard project
Nephew Jonathan
Nephew JonathanOP11mo ago
back (sorry, it's very cold in my apartment right now so I ran the hot water high for a good long while)
Nephew Jonathan
Nephew JonathanOP11mo ago
GitHub
GitHub - cdnilsen/eliotweb
Contribute to cdnilsen/eliotweb development by creating an account on GitHub.
Nephew Jonathan
Nephew JonathanOP11mo ago
It's like that it isn't structured similarly because I'm very much an amateur.
Adam
Adam11mo ago
I’m having a hard time parsing through it, where are the python files?
Nephew Jonathan
Nephew JonathanOP11mo ago
It deployed fine 'till I tried...
Adam
Adam11mo ago
Also, what start command do you run locally?
Nephew Jonathan
Nephew JonathanOP11mo ago
till I tried installing express and mysql py -m http.server oh there are two minor and mostly-irrelevant python files in texts and gentium texts/proofedEditions.py which only contains a list of proofed editions that's from back when this was a local flask app gentium is the font that the stylesheet calls, so I don't mess with it Right now the relevant stuff is --node_modules which can probably be cleaned up and streamlined, but that's another learning curve right now --texts which has the plain text files --textJSON which has JSON files of each book. these are old-ish JSON files which I need to write a new program in JS, they're just copied from an old repository where I used Python to make them
Adam
Adam11mo ago
node_modules can be entirely gitignored, can you do that now?
Nephew Jonathan
Nephew JonathanOP11mo ago
uhhh lessee pff okay just gitignored node_modules (I think!)
Adam
Adam11mo ago
Did you commit it? I’m not seeing it
Nephew Jonathan
Nephew JonathanOP11mo ago
did so just now
Adam
Adam11mo ago
should be node_modules/* not just node_modules/
Nephew Jonathan
Nephew JonathanOP11mo ago
right-oh okay deployment still failing
Adam
Adam11mo ago
Yep that was just a step to clean up the repo, getting on my pc now to troubleshoot more Alright, your repo is very strangely formatted. Is there a reason you stopped using flask? I think that would be the way to go, even though you only have one python file in the entire repo (?)
Nephew Jonathan
Nephew JonathanOP11mo ago
Uh, the reason I stopped using Flask is that I wanted more experience doing this in more-or-less pure JS. If I were to use Flask, how would I have it boot the Flask server up when it opens the webpage?
Adam
Adam11mo ago
Totally makes sense, you should be using a JS framework then rather than just running a python http server There's a lot of work to do there if you want to use a framework, or we can just get this working as hacky as it is. Which would you like to do?
Nephew Jonathan
Nephew JonathanOP11mo ago
I'd like to get it working hackily if I can, and stick to JS and some basic JS libraries. The first thing to fix is obviously just getting it deploying again, then I'd like to figure out how to get FS working or something else that can talk to and update server-side databases or JSONs This doesn't need to be crazy scalable; it's for a small handful of academics.
Adam
Adam11mo ago
Great sounds good. Please create a file called nixpacks.toml with this text:
[start]
cmd = 'py -m http.server'
[start]
cmd = 'py -m http.server'
Nephew Jonathan
Nephew JonathanOP11mo ago
In the top of the repo?
Adam
Adam11mo ago
Yes, at the root
Nephew Jonathan
Nephew JonathanOP11mo ago
gotcha.
Adam
Adam11mo ago
unless you run that command somewhere else in the repo for some reason? When you start locally
Nephew Jonathan
Nephew JonathanOP11mo ago
I don't, I'm just making sure I've got my p's and q's crossed and dotted.
Adam
Adam11mo ago
Got it
Nephew Jonathan
Nephew JonathanOP11mo ago
pushed build failed but I presume in a more interesting fashion, let's see


#9 DONE 0.2s



#10 [stage-0 6/10] RUN --mount=type=cache,id=s/bc3c0308-8834-4245-a622-39de5792aafa-/root/npm,target=/root/.npm npm ci



#10 0.666 npm WARN config production Use `--omit=dev` instead.



#10 2.004

#10 2.004 added 76 packages, and audited 77 packages in 1s

#10 2.004

#10 2.004 11 packages are looking for funding

#10 2.004 run `npm fund` for details

#10 2.006

#10 2.006 found 0 vulnerabilities

#10 DONE 2.0s



#11 [stage-0 7/10] COPY . /app/.



#11 DONE 0.3s



#12 [stage-0 8/10] RUN --mount=type=cache,id=s/bc3c0308-8834-4245-a622-39de5792aafa-node_modules/cache,target=/app/node_modules/.cache CI=false npm run build



#12 0.677 npm

WARN config production Use `--omit=dev` instead.



#12 0.890 npm ERR! Missing script: "build"

#12 0.890 npm ERR!

#12 0.890 npm ERR! To see a list of scripts, run:

#12 0.891 npm ERR! npm run

#12 0.893
#12 0.893 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-01-17T15_50_03_083Z-debug-0.log
#12 ERROR: process "/bin/bash -ol pipefail -c CI=false npm run build" did not complete successfully: exit code: 1
-----
> [stage-0 8/10] RUN --mount=type=cache,id=s/bc3c0308-8834-4245-a622-39de5792aafa-node_modules/cache,target=/app/node_modules/.cache CI=false npm run build:
WARN config production Use `--omit=dev` instead.
0.890 npm ERR! Missing script: "build"
0.890 npm ERR!
0.890 npm ERR! To see a list of scripts, run:
0.891 npm ERR! npm run
0.893
0.893 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-01-17T15_50_03_083Z-debug-0.log
-----
Dockerfile:24
-------------------
22 | # build phase
23 | COPY . /app/.
24 | >>> RUN --mount=type=cache,id=s/bc3c0308-8834-4245-a622-39de5792aafa-node_modules/cache,target=/app/node_modules/.cache CI=false npm run build
25 |
26 |
-------------------
ERROR: failed to solve: process "/bin/bash -ol pipefail -c CI=false npm run build" did not complete successfully: exit code: 1
Error: Docker build failed


#9 DONE 0.2s



#10 [stage-0 6/10] RUN --mount=type=cache,id=s/bc3c0308-8834-4245-a622-39de5792aafa-/root/npm,target=/root/.npm npm ci



#10 0.666 npm WARN config production Use `--omit=dev` instead.



#10 2.004

#10 2.004 added 76 packages, and audited 77 packages in 1s

#10 2.004

#10 2.004 11 packages are looking for funding

#10 2.004 run `npm fund` for details

#10 2.006

#10 2.006 found 0 vulnerabilities

#10 DONE 2.0s



#11 [stage-0 7/10] COPY . /app/.



#11 DONE 0.3s



#12 [stage-0 8/10] RUN --mount=type=cache,id=s/bc3c0308-8834-4245-a622-39de5792aafa-node_modules/cache,target=/app/node_modules/.cache CI=false npm run build



#12 0.677 npm

WARN config production Use `--omit=dev` instead.



#12 0.890 npm ERR! Missing script: "build"

#12 0.890 npm ERR!

#12 0.890 npm ERR! To see a list of scripts, run:

#12 0.891 npm ERR! npm run

#12 0.893
#12 0.893 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-01-17T15_50_03_083Z-debug-0.log
#12 ERROR: process "/bin/bash -ol pipefail -c CI=false npm run build" did not complete successfully: exit code: 1
-----
> [stage-0 8/10] RUN --mount=type=cache,id=s/bc3c0308-8834-4245-a622-39de5792aafa-node_modules/cache,target=/app/node_modules/.cache CI=false npm run build:
WARN config production Use `--omit=dev` instead.
0.890 npm ERR! Missing script: "build"
0.890 npm ERR!
0.890 npm ERR! To see a list of scripts, run:
0.891 npm ERR! npm run
0.893
0.893 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-01-17T15_50_03_083Z-debug-0.log
-----
Dockerfile:24
-------------------
22 | # build phase
23 | COPY . /app/.
24 | >>> RUN --mount=type=cache,id=s/bc3c0308-8834-4245-a622-39de5792aafa-node_modules/cache,target=/app/node_modules/.cache CI=false npm run build
25 |
26 |
-------------------
ERROR: failed to solve: process "/bin/bash -ol pipefail -c CI=false npm run build" did not complete successfully: exit code: 1
Error: Docker build failed
i presume I need to change my build command ah yes i had set it to CI=false npm run build let's kill that excellent! it deploys okay
Adam
Adam11mo ago
Yeah that's the play. When you send logs, can you use this tool? https://bookmarklets.up.railway.app/log-downloader/ It'll get all the lines and puts them all into a file
Nephew Jonathan
Nephew JonathanOP11mo ago
gotcha okay so it now deploys again
Adam
Adam11mo ago
Great, can you access it? through the url I mean
Nephew Jonathan
Nephew JonathanOP11mo ago
Uhh... no, actually... GET https://eliotweb-production.up.railway.app/index.html 503 (Service Unavailable)
Nephew Jonathan
Nephew JonathanOP11mo ago
lessee oh wait i'll need to install python server-side, won't I...?
Adam
Adam11mo ago
Okay, python's not installed. Add this to the top of your nixpacks.toml
[phases.setup]
nixPkgs = ['...', 'python3']
[phases.setup]
nixPkgs = ['...', 'python3']
You also may have to change the start command to say python instead of py
Nephew Jonathan
Nephew JonathanOP11mo ago
aye, i'll try that once it finishes deploying or trying to all righty deployed successfully, now let's see if it crashes... oh wait
Railway Config File Path Location in the repo to a file that contains Railway build and deploy config.
that's currently railway.toml, does it need to be nixpacks.toml
Adam
Adam11mo ago
No, those are two different files. nixpacks.toml controls the build, railway.toml controls railway settings
Nephew Jonathan
Nephew JonathanOP11mo ago
k it failed to respond, so I changed the start command to python
Adam
Adam11mo ago
no logs? If there are no logs, change the start command to python http.server $PORT and add an environment variable called PORT set to 8080
Nephew Jonathan
Nephew JonathanOP11mo ago
uh, oh right
Adam
Adam11mo ago
Those build logs look fine, what about the deployment logs?
Nephew Jonathan
Nephew JonathanOP11mo ago
Those appear to be empty? "No deployment logs. All output sent to stdout will be displayed here"
Adam
Adam11mo ago
That's expected if you're not logging anything when your app starts Sounds like you're not
Nephew Jonathan
Nephew JonathanOP11mo ago
right, okay so like this?
[phases.setup]
nixPkgs = ['...', 'python3']

[start]
cmd = 'python http.server $PORT'
PORT = 8080
[phases.setup]
nixPkgs = ['...', 'python3']

[start]
cmd = 'python http.server $PORT'
PORT = 8080
Adam
Adam11mo ago
No, remove the PORT line from here
Nephew Jonathan
Nephew JonathanOP11mo ago
sorry :( this is all incredibly new to me
Adam
Adam11mo ago
Set environment variables from the environment variables tab on Railway. You can find it on the service page before you click into a deployment no problem, all good
Nephew Jonathan
Nephew JonathanOP11mo ago
all righty building now...
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Nephew Jonathan
Nephew JonathanOP11mo ago
so like this
Adam
Adam11mo ago
Yup you got it
Nephew Jonathan
Nephew JonathanOP11mo ago
says it deployed fine but is still not responding do I need to give it a few?
Adam
Adam11mo ago
No logs?
Nephew Jonathan
Nephew JonathanOP11mo ago
ah, aha python: can't open file '/app/http.server': [Errno 2] No such file or directory do I need to create an empty 'app' folder
Adam
Adam11mo ago
You don't even have an http.server file...
Nephew Jonathan
Nephew JonathanOP11mo ago
look like I said i'm new to this
Adam
Adam11mo ago
No I know, I'm just wondering how it worked before lol
Nephew Jonathan
Nephew JonathanOP11mo ago
I just ran py -m http.server from terminal to work with it locally which seemed to work fine
Adam
Adam11mo ago
You removed the -m from the start command, that's the issue here Please add that back
Nephew Jonathan
Nephew JonathanOP11mo ago
aha hmm still not responding...
Adam
Adam11mo ago
deploy logs?
Nephew Jonathan
Nephew JonathanOP11mo ago
aha! there it is hurrah okay so ...now I should set up a database, perhaps? so JS isn't gonna be very happy working with databases, right or like I should do a Python backend in Flask to do anything involving editing JSONs
Adam
Adam11mo ago
First thing I would do is use a JS framework like react Once you've done that, then you can add a database and store your strings there rather than in text files
Nephew Jonathan
Nephew JonathanOP11mo ago
Well I'll want the text files around anyways because those are what I edit and proofread I...I know people really like frameworks but I'm trying to write this in bare-metal JS to the extent possible oh, uh can I change gitignore back to not ignoring node modules or is that a bad idea but yeah, my main concern right now is just setting up an sql database on the thing and then writing programs that can read from and write to it so i suppose what I'm asking is just what's the easiest way to do that preferably without using any frameworks
Adam
Adam11mo ago
You can kick off a database on Railway by deploying a template from the + icon on the project dashboard Add a postgres or mariadb database from there
Nephew Jonathan
Nephew JonathanOP11mo ago
(why not mysql?)
Adam
Adam11mo ago
Then Google how to connect to the database and run queries and integrate that into your setup mysql is good too It just uses more RAM, so is more expensive mariadb is an optimized version of mysql
Nephew Jonathan
Nephew JonathanOP11mo ago
got it ...will I need to remove node_modules from gitignore i presume I will?
Adam
Adam11mo ago
No, node_modules generally shouldn't be committed
Nephew Jonathan
Nephew JonathanOP11mo ago
got it, okay... (I think) lessee mariadb doesn't show up
Adam
Adam11mo ago
There isn't a reason to commit it since when you build your project it will reinstall all of those modules
Nephew Jonathan
Nephew JonathanOP11mo ago
definitely not mongodb or redis? (mariadb isn't listed)
Adam
Adam11mo ago
No description
Adam
Adam11mo ago
Did you click template before searching?
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Nephew Jonathan
Nephew JonathanOP11mo ago
yep these are the-- oh template
Adam
Adam11mo ago
You can choose whatever you want. In my experience mariadb has been the cheapest option
Nephew Jonathan
Nephew JonathanOP11mo ago
...it needs to be in a separate github repo? seems like I should just create an sqlite3 (or whatever) and setup file locally and commit (unless there's a strong reason to do otherwise, such as that I am talking out of my backside
Adam
Adam11mo ago
Railway's storage is ephemeral. When you kick off a new deploy the filesystem is wiped and reset from the github repo. Since sqlite is an on-disk database system, it will be wiped each time you deploy There are ways to make it not do that, but it's more setup than just deploying a template instead And yes, generally databases should be in a separate service/github repo. Having all your code and processes in one can be a recipe for disaster
Nephew Jonathan
Nephew JonathanOP11mo ago
Got it. Ah, I see... okay, I've got an sqlite3 db set up now in /eliotdb
Adam
Adam11mo ago
So you've decided to do the extra setup? I don't recommend it
Nephew Jonathan
Nephew JonathanOP11mo ago
Oh, sorry :( okay so I should kill that and then do mariadb instead sorry, I misunderstood
Adam
Adam11mo ago
No prob, yes
Nephew Jonathan
Nephew JonathanOP11mo ago
got it. okay, it seems to be...woops okay lessee it automatically mounted to 'data', I had intended to take a screenshot and ask about that but
Adam
Adam11mo ago
data will be a volume, that's correct volumes are a way to avoid the ephemeral storage. They persist between deploys
Nephew Jonathan
Nephew JonathanOP11mo ago
but within the repository, as the server sees it. gotcha
Adam
Adam11mo ago
The template should be fine as is, don't make any changes to it
Nephew Jonathan
Nephew JonathanOP11mo ago
so from the perspective of the pages as deployed, it's within the same folder, but it doesn't live on github okay, because I didn't give it its own repository by accident
Adam
Adam11mo ago
Services don't see each other's filesystems, you'll have to communicate with the db through the url I'm not sure what you mean by this
Nephew Jonathan
Nephew JonathanOP11mo ago
well I told it to mount to /data i think to /data within the repository...lessee okay so how do I talk to it
Adam
Adam11mo ago
You'll have to Google that for yourself, I'm not too familiar with JS
Nephew Jonathan
Nephew JonathanOP11mo ago
gotcha
Nephew Jonathan
Nephew JonathanOP11mo ago
so it looks like this
No description
Adam
Adam11mo ago
I'm confused... Why is it called sqlite3 data? Which service is this data attached to?
Nephew Jonathan
Nephew JonathanOP11mo ago
er... it's attached to eliotweb
Adam
Adam11mo ago
So you DO want to do the complicated setup
Nephew Jonathan
Nephew JonathanOP11mo ago
okay, deleted that no i don't, i made a mistake
Adam
Adam11mo ago
Like I've said, sqlite3 is not the way to go
Nephew Jonathan
Nephew JonathanOP11mo ago
okay i deleted the volume
Adam
Adam11mo ago
Great. Did you make the mariadb service?
Nephew Jonathan
Nephew JonathanOP11mo ago
one minute, redeploying works, good, okay now-- okay
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Nephew Jonathan
Nephew JonathanOP11mo ago
is there anything I want to change here
Adam
Adam11mo ago
Nope, you're good to go
Nephew Jonathan
Nephew JonathanOP11mo ago
cool.
Nephew Jonathan
Nephew JonathanOP11mo ago
MariaDB KnowledgeBase
Getting Started With the Node.js Connector
Available through the Node.js repositories; install using npm.
Nephew Jonathan
Nephew JonathanOP11mo ago
looks like I will need to temporarily de-gitignore node_modules so I can install this, maybe? no. sorry. :( sorry I'm nearly there and will stop being obnoxious soon
Adam
Adam11mo ago
No, you don't. Node_modules is just a cache for your local computer.
Nephew Jonathan
Nephew JonathanOP11mo ago
Okay. But I will want to install it locally and push so that I can use it?
Adam
Adam11mo ago
It's not even properly gitignored right now, I was wrong in my message about that. It should just be

node_modules

node_modules
You would add it to your package.json, then push Like I said I'm not super familiar with JS so I may be wrong about how to install packages. I just know that node_modules should not be committed
Nephew Jonathan
Nephew JonathanOP11mo ago
awrighty. I've now got
{
"dependencies": {
"express.js": "^1.0.0",
"fs": "^0.0.1-security",
"mariadb": "^3.2.3",
"mysql": "^2.18.1"
}
}
{
"dependencies": {
"express.js": "^1.0.0",
"fs": "^0.0.1-security",
"mariadb": "^3.2.3",
"mysql": "^2.18.1"
}
}
and...pushed... okay oh!
The main field is a module ID that is the primary entry point to your program. That is, if your package is named foo, and a user installs it, and then does require("foo"), then your main module's exports object will be returned.

This should be a module relative to the root of your package folder.

For most modules, it makes the most sense to have a main script and often not much else.

If main is not set, it defaults to index.js in the package's root folder.
The main field is a module ID that is the primary entry point to your program. That is, if your package is named foo, and a user installs it, and then does require("foo"), then your main module's exports object will be returned.

This should be a module relative to the root of your package folder.

For most modules, it makes the most sense to have a main script and often not much else.

If main is not set, it defaults to index.js in the package's root folder.
anyways-- @Adam thanks very much for your help
Adam
Adam11mo ago
No prob, happy to help
Nephew Jonathan
Nephew JonathanOP11mo ago
all right so Firebase doesn't appear to be the right choice so back to the drawing board with uh I chose the 'expressjs with postgres' template
Adam
Adam11mo ago
I did say postgres or marian you shouldn’t need to deploy a full stack template, just the single database service aka, just “mariadb” or “postgres”
Nephew Jonathan
Nephew JonathanOP11mo ago
okay so yeah now I have a postgres database aaaand
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Nephew Jonathan
Nephew JonathanOP11mo ago
(how do I set a table column as an array here?)
Adam
Adam11mo ago
word should not be primary key, just fyi
Nephew Jonathan
Nephew JonathanOP11mo ago
All words are unique, though.
Adam
Adam11mo ago
really?
Nephew Jonathan
Nephew JonathanOP11mo ago
This is a concordance database.
Adam
Adam11mo ago
none are repeated? gotcha
Nephew Jonathan
Nephew JonathanOP11mo ago
For this one, yeah, that's why I need verses and versecounts to be arrays. It stores every single verse in the texts where that word occurs, along with how many times in that verse it shows up.
Adam
Adam11mo ago
adding tables is best done through a program like dbgate imo I can walk you through getting that up and running
Nephew Jonathan
Nephew JonathanOP11mo ago
That'd be great, yeah. okay just ran npm install -g dbgate-serve in terminal a handful of deprecated packages...
Adam
Adam11mo ago
that’ll be the dbgate package, that’s not what we’re looking for
Adam
Adam11mo ago
DbGate | Open Source SQL+noSQL Database Client
Powerful cross-platform SQL client and database manager for MySQL, SQL Server, PostgreSQL, SQLite, MongoDB, Redis, Oracle. Fast, modern and 100% free.
Nephew Jonathan
Nephew JonathanOP11mo ago
okay, uninstalled
Adam
Adam11mo ago
download this, connect to your new db using the credentials in the environment variables
Nephew Jonathan
Nephew JonathanOP11mo ago
it's not possible to do this from npm?
Adam
Adam11mo ago
no, npm is a js package installer. this is an app
Nephew Jonathan
Nephew JonathanOP11mo ago
right, downloading now
Adam
Adam11mo ago
actually you’re right, it is possible… I didn’t know that was a thing people did if you want to do that, follow this page
Adam
Adam11mo ago
npm
dbgate-serve
Opensource database administration tool - web interface. Latest version: 5.2.7, last published: 3 months ago. Start using dbgate-serve in your project by running npm i dbgate-serve. There are no other projects in the npm registry using dbgate-serve.
Nephew Jonathan
Nephew JonathanOP11mo ago
can't hurt to have both
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Nephew Jonathan
Nephew JonathanOP11mo ago
okay so what to fill into 'default database' here the url? hmm no that didn't quite work...
Brody
Brody11mo ago
click use database url, then use the database url
Nephew Jonathan
Nephew JonathanOP11mo ago
hmm
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Nephew Jonathan
Nephew JonathanOP11mo ago
oh maybe that was private
Brody
Brody11mo ago
use the variable that isn't private
Nephew Jonathan
Nephew JonathanOP11mo ago
woot okay okay (varchar (250) will have no trouble with unicode, will it...?)
Medim
Medim11mo ago
no I store unicode in varchar
Nephew Jonathan
Nephew JonathanOP11mo ago
great okay so I now have a dummy table with only one column, which is each word and a 'total count' column' all right, so excellent okay, so it showed up so now i need to figure out how to write data to it from the website which i know is going to need front-end / back-end stuff and that is where things get messy
Adam
Adam11mo ago
chatgpt can help you with the code, it’s pretty good with simple stuff like this
Nephew Jonathan
Nephew JonathanOP11mo ago
hold up okay so it says to run node server.js locally so should I add like currently that's really db.js, but should I add like node db.js to the start instructions on the railway app
Adam
Adam11mo ago
right now you’re using python http.server as your start command. As I mentioned yesterday, changing your start command will likely be needed along with potentially reworking your code to fit within a framework so yes, replace python http.server with node db.js to prevent issues going forward I highly recommend spending the time now to standardize your app
Nephew Jonathan
Nephew JonathanOP11mo ago
hmm.
Nephew Jonathan
Nephew JonathanOP11mo ago
well, so I moved db.js into an app folder ah does package.json need to be in that folder too
Adam
Adam11mo ago
honestly, no clue I don’t know js if you’re using chatgpt you could give it your current project structure and ask how you can reformat it
Nephew Jonathan
Nephew JonathanOP11mo ago
yep, this is really useful thanks! i may be back if there's anything big chatgpt can't help w/
Adam
Adam11mo ago
sounds good, good luck
Nephew Jonathan
Nephew JonathanOP11mo ago
oh, yeah okay so my main issue is that the thing seems unable to deploy :/ er
Adam
Adam11mo ago
What are the errors?
Nephew Jonathan
Nephew JonathanOP11mo ago
lemme try restarting the container
Adam
Adam11mo ago
Mind making your repo public again or just inviting me to it?
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Nephew Jonathan
Nephew JonathanOP11mo ago
i mean it's right there and db.js-- yeah no prob one minute
Nephew Jonathan
Nephew JonathanOP11mo ago
GitHub
GitHub - cdnilsen/eliotweb
Contribute to cdnilsen/eliotweb development by creating an account on GitHub.
Nephew Jonathan
Nephew JonathanOP11mo ago
try now i'll be back in a sec, I need to take a shower and do some laundry
Adam
Adam11mo ago
Could be that db.js isn't a module? Or something like that Just because it's a file doesn't mean it's a module That's a code issue, not a Railway issue. I won't be able to help with that
Brody
Brody11mo ago
wat the heck is going on in this repo (no offense)
Nephew Jonathan
Nephew JonathanOP11mo ago
amateur coding :( brb back well don't you declare or not declare something to be a module when it's, like. called oh oh oh hmm lemme try node app/db.js, silly me hmm. nope.
Brody
Brody11mo ago
please take adam's advice here i do know javascript, yet i still dont know what you have going on
Nephew Jonathan
Nephew JonathanOP11mo ago
gotcha (i think) okay maybe I should start over by just having react-app create stuff in a new folder
Adam
Adam11mo ago
If I’m being honest, I would scrap your whole project structure as is and start from scratch. Not deleting code, but reformatting it and getting everything done properly
Nephew Jonathan
Nephew JonathanOP11mo ago
Yeah, that's what I'm thinking of doing.
Adam
Adam11mo ago
if you don’t clean it up, you’re going to look back on it in a few months and not have any idea what’s going on glad to hear it
Brody
Brody11mo ago
what are you trying to achieve? a backend and a frontend?
Nephew Jonathan
Nephew JonathanOP11mo ago
Well, I'll need both to talk to the server, yes?
Adam
Adam11mo ago
the server would be the backend the frontend talks to the backend which talks to the db or is there another server you’re communicating with?
Nephew Jonathan
Nephew JonathanOP11mo ago
Uh, there's a Postgres db I've set up, as I mentioned. I'm currently unfucking a casing issue which is quite common with React stuff and then I'll start rebuilding the thing. pffff no that's also a total mess okay starting again from scratch...
Adam
Adam11mo ago
Yep, I included that. Just wondering if there's another server you're communicating with, but I'm assuming that's not the case
Nephew Jonathan
Nephew JonathanOP11mo ago
Nope.
Brody
Brody11mo ago
you would likely want a structure like this
.
├── backend/
│ └── <node code here>
├── frontend/
│ └── <create react app code here>
└── .gitignore
.
├── backend/
│ └── <node code here>
├── frontend/
│ └── <create react app code here>
└── .gitignore
(the period denotes the root of the repo) two apps, a frontend and a backend, this means you will have two railway services for each app, along with the postgres database, totalling 3 services in your railway project canvas
Nephew Jonathan
Nephew JonathanOP11mo ago
Right, gotcha. Okay, so, lessee...
Brody
Brody11mo ago
just use this as a starting point for the frontend app https://github.com/brody192/create-react-app-starter its ready to run on railway
Nephew Jonathan
Nephew JonathanOP11mo ago
okay. so /src/ is backend and /public/ is frontend?
Brody
Brody11mo ago
everything in the repo i linked gets put into the frontend folder
Adam
Adam11mo ago
I think a key point of confusion here is right now you don't have a backend and frontend They're mashed together
Brody
Brody11mo ago
they do be pretty mashed
Adam
Adam11mo ago
Ideally, you separate them out into the frontend and backend. You could clean up your code and keep them both in the frontend, then just have that directly communicate with the db but best case would be to separate them out
Nephew Jonathan
Nephew JonathanOP11mo ago
right well i just cleaned out the repo (the old stuff is still there so I don't need to rewrite it) so now there's a frontend and backend folder
Adam
Adam11mo ago
pinned your repo so I can find it easily
Nephew Jonathan
Nephew JonathanOP11mo ago
thx
Adam
Adam11mo ago
I think you misunderstood what brody said ^ public and src are both part of the frontend
Adam
Adam11mo ago
No description
Adam
Adam11mo ago
This is all frontend
Nephew Jonathan
Nephew JonathanOP11mo ago
including node-modules?
Brody
Brody11mo ago
you dont want node_modules in the repo anywhere, please remove it
Nephew Jonathan
Nephew JonathanOP11mo ago
okay
Adam
Adam11mo ago
node_modules is in the gitignore... That's weird
Nephew Jonathan
Nephew JonathanOP11mo ago
well, that's what I was suggested to do a while back
Adam
Adam11mo ago
Yeah, but it's not ignoring the folder
Nephew Jonathan
Nephew JonathanOP11mo ago
okay well i have now gotten rid of it so
Brody
Brody11mo ago
this also isnt the frontend code from the repo i linked
Nephew Jonathan
Nephew JonathanOP11mo ago
right just pushed
Adam
Adam11mo ago
that's better
Brody
Brody11mo ago
still not the frontend code from the repo i linked though lol
Nephew Jonathan
Nephew JonathanOP11mo ago
rightoh done okay, added that frontend code
Brody
Brody11mo ago
there will also be no need for that nixpacks.toml file, you may remove it
Nephew Jonathan
Nephew JonathanOP11mo ago
the one in the root? yeah I got rid of that
Brody
Brody11mo ago
cool looks good show me a screenshot of your railway project's canvas please
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Nephew Jonathan
Nephew JonathanOP11mo ago
and then uh what should the custom start command be here do I tell it to use frontend for the root directory? /bin/bash: node: command not found
Brody
Brody11mo ago
remove the start command (and a build command if you have one) then set the root directory to /frontend
Nephew Jonathan
Nephew JonathanOP11mo ago
woot! okay so that works okay so most immediately the postgres databsae consists of uh a table words_diacritics with one row and two columns: "word":"kâh" (primary key), "total_count":1 and so what I would like to do is a proof-of-concept page that can display that, and also add another word with a count
Brody
Brody11mo ago
well then you need to deploy the backend. frontend makes a request to the backend, the backend makes a query on the database, formats the resulting data, returns the formatted data back to the frontend, the frontend displays the data to the user to deploy the backend you need a /backend folder with your backend code in the repo located within that folder, then you need to create another railway service in the same railway project, and set its root directory to /backend
Nephew Jonathan
Nephew JonathanOP11mo ago
ahhhh okay... okay I think I am going to go try and find some lunch and then work on my own thanks so much!
Brody
Brody11mo ago
no problem!
Nephew Jonathan
Nephew JonathanOP11mo ago
So-- So, React is frontend only right? How do I have it talk to backend? hmm okay so I can use express in the backend...
Brody
Brody11mo ago
yeah write an express app the express code will live in a /backend folder within your repo
Nephew Jonathan
Nephew JonathanOP11mo ago
Right, right. With your frontend React app, how does it know in the first place that--I don't see index.js being called from index.html?
Adam
Adam11mo ago
React is smart, it knows that files with the same name should be used together
Nephew Jonathan
Nephew JonathanOP11mo ago
OK. So what do I need to put in the backend? server.js and then... oh, should I like set up an express app from npm while terminal is in the backend folder that would be sensible...
Nephew Jonathan
Nephew JonathanOP11mo ago
so like i should cd backend, then do npm install express? okay but now there are node modules in the backend. that's still kosher?
Brody
Brody11mo ago
its fine locally, just dont let that folder make it to the repo, make sure its being gitignored
Nephew Jonathan
Nephew JonathanOP11mo ago
could I delete it with no ill effects? or, I suppose I'll need to have it around to mess w/ it locally lessee, uh
Brody
Brody11mo ago
you need it locally, make sure it get gitignored
Nephew Jonathan
Nephew JonathanOP11mo ago
i can have two separate gitignore files in frontend and backend right
Brody
Brody11mo ago
yes
Nephew Jonathan
Nephew JonathanOP11mo ago
all righty so that should just be node_modules with no slashes right okay, so, lessee all right and then if I added index.js, I should have node index.js as the start command in the backend service on Railway
Brody
Brody11mo ago
heres a good resource to have on hand https://www.toptal.com/developers/gitignore/
Nephew Jonathan
Nephew JonathanOP11mo ago
Thanks! OK, so
Nephew Jonathan
Nephew JonathanOP11mo ago
DEV Community
Connect a Railway database(postgreSQL) with node-postgres in Express
There are two options for connecting to Railway's postgres database. Using a connection string or a...
Brody
Brody11mo ago
bro slow down
Nephew Jonathan
Nephew JonathanOP11mo ago
sorry
Brody
Brody11mo ago
get a hello world demo running on railway first an express app that just returns a json message when you visit
Nephew Jonathan
Nephew JonathanOP11mo ago
right well right now, index.js is still uh
const express = require("express");
const app = express();

app.get("/", (req, res) => {
res.send("Hello, World!");
});

const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
const express = require("express");
const app = express();

app.get("/", (req, res) => {
res.send("Hello, World!");
});

const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
now do I need to change the port to the port on the postgres database?
Brody
Brody11mo ago
the express server has nothing to do with postgres, but that does look like it will work
Nephew Jonathan
Nephew JonathanOP11mo ago
right, okay well then ignoring that port anyways... And then res.send is the piece that talks to the frontend?
Brody
Brody11mo ago
no, that sends a response to the http request
Nephew Jonathan
Nephew JonathanOP11mo ago
i see...
Brody
Brody11mo ago
lets just get this running on railway first read here please
Nephew Jonathan
Nephew JonathanOP11mo ago
Right, I've got that. There's eliot-backend and eliot-frontend on railway and they're deploying from the backend and frontend folders respectively.
Brody
Brody11mo ago
gotta stop doing this https://github.com/cdnilsen/eliotweb/blob/main/backend/db.js#L5 use environment variables please
Nephew Jonathan
Nephew JonathanOP11mo ago
sorry :/ okay, uh ...environment variables don't seem to be listed on the postgres service? only service variables lessee what google says
Adam
Adam11mo ago
Service variables are environment variables they're environment variables specific to that service
Brody
Brody11mo ago
yep and you need to create a new railway service in your project to run the backend
Nephew Jonathan
Nephew JonathanOP11mo ago
Wait, a second service to run the backend?
Brody
Brody11mo ago
of course
Nephew Jonathan
Nephew JonathanOP11mo ago
so I need more than just eliot-frontend and eliot-backend?
Adam
Adam11mo ago
Yes, the frontend and backend should be run separately
Nephew Jonathan
Nephew JonathanOP11mo ago
afaik they are?
Adam
Adam11mo ago
Did you name your database backend?
Nephew Jonathan
Nephew JonathanOP11mo ago
No, it's called...it's just called Postgres I could change the name
Adam
Adam11mo ago
Nope, it should just be called postgres
Brody
Brody11mo ago
pictures are worth 1000 words, so please show us a screenshot of your railway project
Adam
Adam11mo ago
You've called your db backend before, just making sure
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Brody
Brody11mo ago
looks good
Adam
Adam11mo ago
Looks good. Your backend and frontend are in different services
Brody
Brody11mo ago
is the backend's root directory set to /backend?
Nephew Jonathan
Nephew JonathanOP11mo ago
Yep.
No description
Brody
Brody11mo ago
generate a domain for it
Nephew Jonathan
Nephew JonathanOP11mo ago
all righty it's now at eliotweb-backend-production.up.railway.app (frontend is at https://eliotweb-production.up.railway.app/)
Brody
Brody11mo ago
thats going to take a bit to come alive since you just created it
Nephew Jonathan
Nephew JonathanOP11mo ago
sure well
Brody
Brody11mo ago
its live now
Nephew Jonathan
Nephew JonathanOP11mo ago
whaddya know
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Nephew Jonathan
Nephew JonathanOP11mo ago
yep okay, so how do I un-expose the postgres URI
Brody
Brody11mo ago
now the rest is up to you
Nephew Jonathan
Nephew JonathanOP11mo ago
okay. great! (I think) since unexposing the db uri is almost certainly the thing to do most immediately (should I nuke the current postgres and start a new one for that reason?) (it has basically nothing on it that I can't redo easily from dbgate)
Brody
Brody11mo ago
yeah you leaked the username and password, delete it, create a new one, once done: in railway on your backend service set a service variable DATABASE_URL=${{Postgres.DATABASE_URL}} then in code use process.env.DATABASE_URL instead of the url string
Nephew Jonathan
Nephew JonathanOP11mo ago
okay. so instead of this...
const { Pool } = require("pg");

// The secret connection string you copied earlier
const connectionString =
"OOPS";

const pool = new Pool({
connectionString,
});

module.exports = pool;
const { Pool } = require("pg");

// The secret connection string you copied earlier
const connectionString =
"OOPS";

const pool = new Pool({
connectionString,
});

module.exports = pool;
i want uh
const { Pool } = require("pg");

// The secret connection string you copied earlier
const dbURL = process.env.DATABASE_URL;

const pool = new Pool({
dbURL,
});

module.exports = pool;
const { Pool } = require("pg");

// The secret connection string you copied earlier
const dbURL = process.env.DATABASE_URL;

const pool = new Pool({
dbURL,
});

module.exports = pool;
?
Brody
Brody11mo ago
please read my message again
Nephew Jonathan
Nephew JonathanOP11mo ago
ah, right--
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Nephew Jonathan
Nephew JonathanOP11mo ago
awright
Brody
Brody11mo ago
perfect
Nephew Jonathan
Nephew JonathanOP11mo ago
righty, okay. uh it isn't console.logging anything like it should, but
Brody
Brody11mo ago
show me your db.js code
Nephew Jonathan
Nephew JonathanOP11mo ago
const { Pool } = require("pg");

// The secret connection string you copied earlier
const dbURL = process.env.DATABASE_URL;

const pool = new Pool({
dbURL,
});

module.exports = pool;
const { Pool } = require("pg");

// The secret connection string you copied earlier
const dbURL = process.env.DATABASE_URL;

const pool = new Pool({
dbURL,
});

module.exports = pool;
and then index.js is:
const express = require("express");
const app = express();

app.get("/", (req, res) => {
res.send("Hello, World!");
});

const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
const express = require("express");
const app = express();

app.get("/", (req, res) => {
res.send("Hello, World!");
});

const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
Brody
Brody11mo ago
close enough
Nephew Jonathan
Nephew JonathanOP11mo ago
it should be logging the port to console, though, no?
Brody
Brody11mo ago
check the deploy logs
Nephew Jonathan
Nephew JonathanOP11mo ago
Server running on port 7935
oh, so it logs it to the railway console rather than browser?
Brody
Brody11mo ago
its a web server, console logs go to the place the server is running on
Nephew Jonathan
Nephew JonathanOP11mo ago
gotcha. okay, well, I think I have annoyed you enough for now, and I think I do owe you a coffee, so let me do that now to get backend talking to frontend
Brody
Brody11mo ago
other way around see this message for the flow
Nephew Jonathan
Nephew JonathanOP11mo ago
sorry just one last thing: The port for the postgres database is 14224, but the backend says it is running on 7935.
Brody
Brody11mo ago
express has nothing to do with postgres the ports being different is how it's supposed to be, it's of no concern
Nephew Jonathan
Nephew JonathanOP11mo ago
gotcha
Brody
Brody11mo ago
oh just saw the trains, thank you very much!!!
Nephew Jonathan
Nephew JonathanOP11mo ago
no problem! and then for the uh if I have a wordeditor.js file in the backend to look at the words_diacritics table in the database (which I'd cribbed off an online example) it has uh
const Pool = require("pg").Pool;
const pool = new Pool({
user: "my_user",
host: "localhost",
database: "my_database",
password: "root",
port: 5432,
});
const Pool = require("pg").Pool;
const pool = new Pool({
user: "my_user",
host: "localhost",
database: "my_database",
password: "root",
port: 5432,
});
and I assume I want to use like
Brody
Brody11mo ago
you have already created a pool in your db.js file, use that pool
Nephew Jonathan
Nephew JonathanOP11mo ago
port = process.env.PORT oh, okay
Brody
Brody11mo ago
please remember that the port express runs on has nothing to do with postgres
Nephew Jonathan
Nephew JonathanOP11mo ago
right. so do I import pool into wordeditor.js?
Brody
Brody11mo ago
sounds about right
Nephew Jonathan
Nephew JonathanOP11mo ago
lesseeee so now I have
//wordeditor.js
import pool from "./db.js";

const getWords = async() => {
try {
return await new Promise(function (resolve, reject) {
pool.query("SELECT * FROM words_diacritics", (error, results) => {
if (error) {
reject(error);
}
if (results && results.rows) {
resolve(results.rows);
} else {
reject(new Error("No results found"));
}
});
});
} catch (error_1) {
console.error(error_1);
throw new Error("Internal server error");
}
};
//other functions

module.exports = {
getWords,
addWord,
deleteWord,
updateWord,
};
//wordeditor.js
import pool from "./db.js";

const getWords = async() => {
try {
return await new Promise(function (resolve, reject) {
pool.query("SELECT * FROM words_diacritics", (error, results) => {
if (error) {
reject(error);
}
if (results && results.rows) {
resolve(results.rows);
} else {
reject(new Error("No results found"));
}
});
});
} catch (error_1) {
console.error(error_1);
throw new Error("Internal server error");
}
};
//other functions

module.exports = {
getWords,
addWord,
deleteWord,
updateWord,
};
now...let's say I want to getWords somewhere else oh, hmm in my frontend, could I just do: declare index.js to be a module, import getWords from ../backend/wordeditor.js?
Brody
Brody11mo ago
your backend and frontend code is separate, please dont start mixing them again first, your backend would need to return these words via a json api so dont touch the frontend until your backend can do that
Nephew Jonathan
Nephew JonathanOP11mo ago
rightoh. is there a good guide to doing that?
Brody
Brody11mo ago
watch some youtube tutorials? ask chat gpt?
Nephew Jonathan
Nephew JonathanOP11mo ago
yeah, i've found a couple of articles hmm hmrr
Brody
Brody11mo ago
perfect
Nephew Jonathan
Nephew JonathanOP11mo ago
For what the example has as
app.use(function (req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "http://localhost:3000");
res.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
res.setHeader(
"Access-Control-Allow-Headers",
"Content-Type, Access-Control-Allow-Headers"
);
next();
});
app.use(function (req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "http://localhost:3000");
res.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
res.setHeader(
"Access-Control-Allow-Headers",
"Content-Type, Access-Control-Allow-Headers"
);
next();
});
do I replace localhost:3000 with process.env.DATABASE_URL?
Brody
Brody11mo ago
again, express itself has nothing to do with postgres please please remember that
Nephew Jonathan
Nephew JonathanOP11mo ago
right, right...
Brody
Brody11mo ago
but use the cors middleware from express
Nephew Jonathan
Nephew JonathanOP11mo ago
It also didn't like when I tried uh so db.js is
const { Pool } = require("pg");

// The secret connection string you copied earlier
const dbURL = process.env.DATABASE_URL;

const pool = new Pool({
dbURL,
});

module.exports = pool;
const { Pool } = require("pg");

// The secret connection string you copied earlier
const dbURL = process.env.DATABASE_URL;

const pool = new Pool({
dbURL,
});

module.exports = pool;
and then in wordeditor.js I have
import { pool } from "./db.js";

const getWords = async() => {
try {
return await new Promise(function (resolve, reject) {
pool.query("SELECT * FROM words_diacritics", (error, results) => {
if (error) {
reject(error);
}
if (results && results.rows) {
resolve(results.rows);
} else {
reject(new Error("No results found"));
}
});
});
} catch (error_1) {
console.error(error_1);
throw new Error("Internal server error");
}
};
import { pool } from "./db.js";

const getWords = async() => {
try {
return await new Promise(function (resolve, reject) {
pool.query("SELECT * FROM words_diacritics", (error, results) => {
if (error) {
reject(error);
}
if (results && results.rows) {
resolve(results.rows);
} else {
reject(new Error("No results found"));
}
});
});
} catch (error_1) {
console.error(error_1);
throw new Error("Internal server error");
}
};
and the deploy logs said that import wasn't valid because it wasn't a module, or something
/app/wordeditor.js:1

import pool from "./db.js";

^^^^^^

SyntaxError: Cannot use import statement outside a module
/app/wordeditor.js:1

import pool from "./db.js";

^^^^^^

SyntaxError: Cannot use import statement outside a module
(but wordeditor exports its functions, so)
Brody
Brody11mo ago
common nodejs issue that people run into, theres lots of information on it online
Nephew Jonathan
Nephew JonathanOP11mo ago
(also got cors installed) right like there's only one package.json file in backend right
Brody
Brody11mo ago
yeah thats normal
Nephew Jonathan
Nephew JonathanOP11mo ago
so, added "type": "module", to that ...giving me the same thing maybe i need to use const...require instead of import aha!
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Nephew Jonathan
Nephew JonathanOP11mo ago
still an issue, but a better issue
Brody
Brody11mo ago
check your deploy logs
Nephew Jonathan
Nephew JonathanOP11mo ago
Server running on port 6063

Error: connect ECONNREFUSED ::1:5432

at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {

errno: -111,

code: 'ECONNREFUSED',

syscall: 'connect',

address: '::1',

port: 5432

}
Server running on port 6063

Error: connect ECONNREFUSED ::1:5432

at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {

errno: -111,

code: 'ECONNREFUSED',

syscall: 'connect',

address: '::1',

port: 5432

}
okay so this is one of those, I have called the postgres port when I needed to call the local port or vice versa yes?
Brody
Brody11mo ago
show me your db.js file
Nephew Jonathan
Nephew JonathanOP11mo ago
const { Pool } = require("pg");

const dbURL = process.env.DATABASE_URL;

const pool = new Pool({
dbURL,
});

module.exports = pool;
const { Pool } = require("pg");

const dbURL = process.env.DATABASE_URL;

const pool = new Pool({
dbURL,
});

module.exports = pool;
Brody
Brody11mo ago
show me your service variables on the backend
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Brody
Brody11mo ago
is this even the right syntax lol
Nephew Jonathan
Nephew JonathanOP11mo ago
quite possibly not...?
Brody
Brody11mo ago
have a read of pg's docs
Nephew Jonathan
Nephew JonathanOP11mo ago
hmmm
Brody
Brody11mo ago
looks like the correct syntax is const pool = new Pool(dbURL);
Nephew Jonathan
Nephew JonathanOP11mo ago
hmm okay, that gives me new and interesting errors thanks! i think i'm gonna call it for the evening
Brody
Brody11mo ago
alright!
Nephew Jonathan
Nephew JonathanOP11mo ago
morning on the rec of a friend, I have switched to next.js
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/railway/node_modules/react
npm WARN react@"^16.13.1" from [email protected]
npm WARN node_modules/railway
npm WARN railway@"^2.0.17" from the root project
npm WARN 4 more (ink, ink-link, ink-select-input, ink-text-input)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer react@"^17.0.2" from [email protected]
npm WARN node_modules/railway/node_modules/react-reconciler
npm WARN react-reconciler@"^0.26.2" from [email protected]
npm WARN node_modules/railway/node_modules/ink
npm WARN
npm WARN Conflicting peer dependency: [email protected]
npm WARN node_modules/react
npm WARN peer react@"^17.0.2" from [email protected]
npm WARN node_modules/railway/node_modules/react-reconciler
npm WARN react-reconciler@"^0.26.2" from [email protected]
npm WARN node_modules/railway/node_modules/ink
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/railway/node_modules/react
npm WARN react@"^16.13.1" from [email protected]
npm WARN node_modules/railway
npm WARN railway@"^2.0.17" from the root project
npm WARN 4 more (ink, ink-link, ink-select-input, ink-text-input)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer react@"^17.0.2" from [email protected]
npm WARN node_modules/railway/node_modules/react-reconciler
npm WARN react-reconciler@"^0.26.2" from [email protected]
npm WARN node_modules/railway/node_modules/ink
npm WARN
npm WARN Conflicting peer dependency: [email protected]
npm WARN node_modules/react
npm WARN peer react@"^17.0.2" from [email protected]
npm WARN node_modules/railway/node_modules/react-reconciler
npm WARN react-reconciler@"^0.26.2" from [email protected]
npm WARN node_modules/railway/node_modules/ink
i ran npm i -g npm-check-updates, then ncu -u, then npm -i, and it still squawks about this...
Nephew Jonathan
Nephew JonathanOP11mo ago
hmm still got this after switching to Yarn but far fewer warnings about dependencies
Adam
Adam11mo ago
chatgpt it? chatgpt is good at solving most code issues and interpreting logs
Brody
Brody11mo ago
switching from express to next, switching from npm to yarn. are you trying to make this project harder on yourself lol
Nephew Jonathan
Nephew JonathanOP11mo ago
okay, friend made a basic version to talk to the server er but he put some TS in /src/, which compiles to /dist/ if I run tsx -w--but then it ends up in dist per the tsconfig so do I need to do like can I run ../src/ tsx -w as a build command in the backend and then set it to be calling its code from /dist/ i mean, i can run npx tsc on each of the TS files in there but still but doing so doesn't work for index.ts hmm okay killed one of my services and now have only postgres and a single service which gets its stuff from the top directory, and runs npm start as its start command oh right uh i can add a connection of sorts as a service variable in the service... okay so
Nephew Jonathan
Nephew JonathanOP11mo ago
No description
Nephew Jonathan
Nephew JonathanOP11mo ago
awright lessee added a bunch of extra service variables to try and call the pool oh i bet the issue is that I was using the database port in index.ts finally got the damn thing working thanks all
Brody
Brody11mo ago
just woke up, but glad you got it working!!
Want results from more Discord servers?
Add your server