DEV Community

Stenio Wagner
Stenio Wagner

Posted on

[A RESTful API BUILT IN NODEJS USING JUST NATIVE MODULES - NO NPM HERE!]

Hey, people!

Well, I've been using express for routing and mongoose/sequelize to connect my server with my database for a while, and just wanted to try to build my own router and my own database-connector and use them to build a RESTful API using just native modules. :man-shrugging::skin-tone-5:
In this project, I implemented (and much more):

Instant updates on the sever when some file is edited (as nodemon does).
Routing using the Middleware pattern (as express does).
Schema definition to define the data structures used to define the API entities.
Validate the data before save or update using the pre-defined Schema.

Ok, now you're maybe thinking: "What? We already have some libs that someone else created that helps us to do it all (as express and mongoose and mongoose/sequelize that I mentioned)! Why re-invent the wheel"?

And I'll answer you: And I answer you: I know we don't always have time to implement our own ideas to solve certain problems that we face in our daily lives as engineers who use programming to create solutions, but I really want to encourage you, whenever possible, to try to build your own solutions and codify your ideas for these problems, this will make you a much more independent developer and of course much more confident in using a programming language. Apart from the fact that of course this experience will make you expand your knowledge
and make you feel amazing while implementing each feature (as I'm feeling now)!

PS: Treat this project as a personal challenge that I set myself, so there is no intention of running this API in production. Therefore,
This project is not a perfect solution and certainly not better than the ones that already exist in the market, but I want to share this knowledge I learned and implemented with the community so that everyone can benefit from what I did!

Without further ado, here's the repo!

https://github.com/steniowagner/restful-npmless-api

Top comments (4)

Collapse
 
benbot profile image
Benjamin Botwin

I don't know why you'd do this to yourself, but nice job!

Really cool repo to pick through

Collapse
 
mburszley profile image
Maximilian Burszley • Edited

Fundamental knowledge is important to know where to start troubleshooting where application errors are. These exercises refresh (or start) what we know about the barebones level of our code.

Collapse
 
benbot profile image
Benjamin Botwin

I get that. I was making a joke. Sarcasm is hard to express over text :(

Collapse
 
fluffynuts profile image
Davyd McColl

it's good to implement the regular nuts and bolts -- at the very least, it gives us insight into how the clockwork of all things works and more respect for the libraries we depend upon (: