Let's create a CRUD rest API in JavaScript, using:
Node.js
Express
Sequelize
Postgres
Docker
Docker Compose
All the code is available in th...
For further actions, you may consider blocking this person and/or reporting abuse
Hello!
I think this read was quite interesting, good guide.
There were however a few things i noticed that I don't often see in modern JavaScript programming.
Usually you would avoid chaining calls with ".then" since it is bad practice, use "await" instead. Is there a reason why you chain your calls like this even when it's bad practice?
Exporting arrow functions in the controller leads to poor readability and is also not a common way to handle controllers. You would probably want to create a class that represents the controller and export that class. Do you have a reason for exporting arrow functions?
Something that I was wondering throughout the guide was why you use "require" instead of "import", basically why commonjs instead of esm? Commonjs is since long dying and i would not recommend using it.
The JavaScript code in the guide seems to be quite old and I would be careful if I were to use it.
nice breakdown Anton! this is not optimized and it's meant to get things fast. the focus here was more on creating the endpoints and the docker image and the connection with the db.
about the async await, I just used the suggested code, but in other guides I used the await, honestly I prefer that one
this is not meant to be a production ready code, but it's a way to undesrtand the basics!
Thanks for your feedback, I will probably level up the code in the next guide!
Thank you for the explanation!
I was happy to see such a thorough guide as a whole.
It was interesting to see how you containerize the application and I also liked the testing of the end product using Postman and TablePlus, great tools.
Thank you for the guide!
my idea was to start with this and maybe focus more on the upcoming Typescript example. this article is a breakthrough of something I coded live on youtube.
Thank yuo for your feedback, highly appreciated instead of the usual "asweome" comment! 💙
A typescript version would be great! Thanks for your effort.
Awesome! 😄
it's on the todo list. thanks
Thanks for this tutorial @francescoxx
When I run this on my machine, although the server is started, it is stuck when calling the endpoint. It does not returning the response.
Im currently using mac with m1 chip. Any pointers about this?
try docker ps -a. can you see the containers up and running?
Oh, this is because i missed the
next()
function call.oh I see! glad you fixed it
It is actually running
in the index.js, i tried to commented out these lines and it is working now:
I still don't understand what happened. Any pointers / explanation would be appreciated much.
Thanks so much for detailed course. Just a correction in link,
The youtube link that you have kept in the bottom of the course content takes to "Build a CRUD Rest API with Kotlin, Postgres, Docker and docker compose" instead of "JavaScript CRUD Rest API using Nodejs, Express, Sequelize, Postgres, Docker and Docker Compose", it should be updated to https://www.youtube.com/watch?v=Uv-jMWV29rU&t=236s
fixed, thanks!
Thank you Francesco.
you are welcome Mude
Well written and documented. Thanks a ton! But i've got one doubt regarding docker compose and docker build. Arent we supposed to build the image first and name it node_live_app using the docker build command and then execute docker compose build?
no, docker compose build just builds the image. you can even just run docker compose up --build , or docker compose up.
I just did it to show the step-by-step commands to make it clearer
Oh okay. Thank you!
you are welcome
Great post!
thanks Bobby!
This is a first class tutorial. Very clear and precise.
I’ve been a server side Dev for nearly 20 years, using a language called Coldfusion. In Coldfusion we have a tag called CFQUERY, which we can write SQL, inside.
So, for example:
Obviously, you can write extremely complex SQL queries here.
I have only been using NodeJs for a few years now and have always wondered how easy it is to increase the complexity of the SQL query in a NodeJS Rest API application?
CRUD is all very well and is great for highlighting the basics, but, in the real world, business requirements might warrant more complexity?
Hi Francesco
I have set up a codesandbox VM, to try and emulate this tutorial.
I see that your table is called:
But you connect via:
How does your code find the Users table?
I am new at coding. Will try it on the weekend. Thank you for this tutorial.
please let me know if it worked. thank you
Finaly I tested it today.
It worked very well.
a little spelling mistakes in "docker-compose" for starting the second container, but this was easy to fix.
now I can make a little backend for testing in local network :D
Thank you so much.
amazing, glad it helped. do you mean a spelling mistake on your end or in the tutorial?
A few weeks ago, I've discover postgrest, just crazy easy. postgrest.org/en/stable/index.html
It's also open data, directly query your postgresql db just using URIs.
Nice write up! If I ever use this stack I’ll be sure to keep this article nearby.
thank you Toul!
nice article, i learnt a lot, u keep inspiring me fran
thank you Ebuka!
you're welcome, now let me use your tutorial article & practicccccccccccccce
good luccccccck
Will use this one day. Thanks for sharing and making a detailed article.
you are welcome
Welldone Boss
you are welcome
This is beautiful. Never tried Postgres with Node and Express, before, but this is surely gonna help. Thanks.
you are welcome!
Nice post 👍
you are welcome
Amei o post
🔥
Awesome ! <3
thank you
Time to use this for an idea I have....
good luck
WOW,What a great knowledge you have shared Francesco.
thank you @noibisdev
Thanks for sharing, well explained and documented 😁
thank you @Lotfij
A great resource for anyone looking to build a CRUD API..
thank you @codeofrelevancy !!
Great post. It's been long since I last used express and sequelize.
Too bad there's no validation for incoming data.
indeed. there are probably other ways to validate input tho and I should double check
Something missin... hmm, maybe that's typescript i guess
ye probably
Great blog
Pradumna the best!
Thanks a lot !
you are welcome
Amazing! Thank you for the post.
you are welcome Rafael
fantastic post Francesco, what excellent details you have offered.
I'm grateful.
you are welcome Alex!
Great post, thanks for sharing!
Thank you Danilo, highly appreciated!
Hello Francesco,
i really enjoyed the tutorial but i am stuck in the tableplus step. When i connect with the node_live_db its not empty
Any ideas why that happened?
interesting, can you try to remove the volume and try again? of course be careful if you are ona production environment!!
Still the same, i first stopped the container and deleted the volume and recreated it and second try i stopped the container and i changed the docker-compose.yml file volumes part with
volumes:
# node_db_data: {} # remove the old volume
data: {} # create a new volume
to maybe create a new db folder, but both tries it was not empty.
I also installed psql to check the db and i get that "i did not find any relations" when i typed \dt
try to copy past my docker compose and try agaqin