DEV Community

Cover image for Hugo - sending hugs you really feel - The backend
Nagy Szabolcs
Nagy Szabolcs

Posted on

2 1

Hugo - sending hugs you really feel - The backend

The API 🤖

For the backend, I decided to go with a Node and Express combination.
My idea is to have 3 endpoints

Endpoint Behavior
GET api/:id responds with the given hug's data
POST api/?pattern={}&name="" adds a new hug to the database
POST api/:id increments the number of plays in the database

and to make calls from the HTML page to these.

Coding the backend was pretty straightforward because I worked with this kind of environment before.
The one issue I ran into multiple times tho was to do with CORS when connecting to the api from localhost. This time the api was on the DigitalOcean servers so I expected to encounter some issues.
I fixed these by adding this regex rule in the DigitalOcean panel .* which basically enables every source.

The database 🛢

I initially wanted to use a NoSQL database, but since I was running out of time quickly, I decided to go with PostgreSQL because that was the only option on the app platform.

I worked with SQL databases before, but one new thing I learned about was the JSONB Datatype. Turns out, you can conveniently store JSON data in traditional SQL databases. 😅
At first, I actually tried using JSON instead, but since I saved my patterns in a JSON array it couldn't be done.

Final thoughts 💭

Overall I managed to finish everything in a day or so!

Oh and, I haven't told you about the JavaScript behind the websites. Honestly they are pretty boring, just getting states from buttons and API calls, nothing fancy.

Anyways take care, and have a hug! 👻
hug gif

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay