taniarascia / comments

Comments
7 stars 0 forks source link

node-express-postgresql-heroku/ #58

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Build a Node.js, Express, & PostgreSQL REST API | Tania Rascia

Recently, I wanted to create and host a Node server, and discovered that Heroku is an excellent cloud platform service that has free hobby…

https://www.taniarascia.com/node-express-postgresql-heroku/

carolinadeff commented 3 years ago

Thanks for this tutorial, cleared many things for me!!

VincenzoMarcovecchio commented 3 years ago

How would you type this command on windows cat init.sql | heroku pg:psql postgresql-whatever-00000 --app example-node-api ? am I missing something? thanks

pvaladez commented 3 years ago

@VincenzoMarcovecchio - Windows doesn't have the cat command... you could try "type": https://superuser.com/questions/434870/what-is-the-windows-equivalent-of-the-unix-command-cat

However, Tania is using MacOS in this tutorial, so I wouldn't be surprised if you come across other differences in trying to make it work natively on Windows. You might want to consider installing WSL for Windows and running Ubuntu to make the commands more similar, but either way you'll probably need to research some OS specifics.

raulavilesrodriguez commented 3 years ago

Hi Tania, the app on localhost works fine but on heroku I get an error when opening the app. In heroku in Config Vars I wrote NODE_ENV: production PORT: 5432. But it doesn't work

VincenzoMarcovecchio commented 3 years ago

Hey @raulavilesrodriguez I fixed this problem by setting the server to be listening to process.env.PORT when in production, it's an heroku thing that should fix it

JorgenNyborgChristensen commented 3 years ago

@raulavilesrodriguez change ssl: isProduction to ssl: { rejectUnauthorized: false }

Source: https://devcenter.heroku.com/articles/getting-started-with-nodejs?singlepage=true#provision-a-database

Fullchee commented 3 years ago

Thank you so much for this amazing tutorial!

One update since it was written: body-parser got added back to express.

I got a deprecated error in VSCode so this is what I needed to do

bodyParser.json()
bodyParser.urlencoded(...)

use express

express.json()
express.urlencoded(...)

http://expressjs.com/en/api.html#express.urlencoded

agan-k commented 3 years ago

Thanks @JorgenNyborgChristensen ssl: { rejectUnauthorized: false } This definitely worked for me.

PugmanD commented 3 years ago

The frontend isn't working it is saying await only works in async functions can anyone help me?

RizaHKhan commented 3 years ago

@PugmanD are you writing async before the function name?

Ie:

async myFunc(){}
AndresSalomon1990 commented 3 years ago

Thanks for this Tania, you are amazing! Just a question, what do you think about using Sequelize instead of node-postgres?

taniarascia commented 3 years ago

Glad you liked it, @AndresSalomon1990. I don't have an opinion on Sequelize since I've never used it.

Dylan-Cairns commented 2 years ago

Thank you for this Tania! I used this to extend an app I started by following your excellent MVC tutorial!

Can anyone point me to a resource on how to properly display error messages on the client side that are returned from express-validator when attempting to insert into the database via the fetch api?