ExpressJs is a minimal and flexible Node.js web application framework that is minimal, lightweight and easy to use. Express has made it easy to write backend and build REST API's code in JavaScript.
If you are lazy like me, you can directly download my script from here
Or
Run the following code
Or
Continue Installation
Make sure you have nodejs installed.
Follow the steps
This is how you can run the server
Now copy the following code in your package.json
file
Now run npm run dev
to start the server in dev mode.
TypeScript
If you are using TypeScript, you can follow the steps below
Now setup your tsconfig.json
file
Now write the app code
copy the scripts to your package.json
Now run npm run dev
to start the server in dev mode.
Configuring ORMS
An ORM(Object Relational Mapping) is a programming technique for converting data between incompatible type systems in object-oriented programming languages.
But I don't want to write Object oriented code in JavaScript. I prefer to write SQL queries.
But listen me out, ORMs are not that bad. They can save you a lot of time and effort.
2 of my favorite ORMS are Mongoose for MongoDB and Prisma for SQL based databases. [ Honorable Mention: Sequelize ]
Mongoose
Mongoose is pretty easy to use and MongoDB's best part is its mostly free and easy to work with.
Just run
Prisma
Prisma's models, relation patterns and queries are very easy to use and understand.
Just run
Conclusion
You are mostly done with setting up express. I used to think backend is just writing routes fetching data from database and sending it to the client. But it's more than that. You have to think about security, performance, scalability and a lot more.
After joining a company, I have worked more on designing databases, integrating with third party services(with poor documentation), dockerizing the app. I have learned a lot and I am still learning.
Thank you for reading this article. I hope it helps 🙏.