I had a chance to try Node.js framework last month; I decided to build REST APIs using Node.js and express.js. Regularly I'm using JavaScript in my daily work besides using Django to build Web Applications, but many times I need to develop a front-end feature, This when I need to use JavaScript. I'm always using JavaScript to write front-end logic, but I never wrote back-end logic using it. I took the challenge to develop a simple REST APIs using express.js.
Development environment
To start developing, I need to get my machine ready, so I installed node.js via Homebrew (I'm a macOS user), it is quite easy, and node.js installation comes with npm "npm is a package manager for node.js it is like pypi or pip for Python". I used Visual Studio Code as a text editor. Now I'm ready to go ๐ช๐ป.
What I've learned?
While building the REST APIs, I've learned many things, mainly that I'm experiencing the new development stack. Let's see the parts I've learned.
Node.js
Node.js is a back-end engine; it is using Google Chrome V8 JavaScript engine to run JavaScript code on your machine instead of a browser. Node is not a language it is an engine.
Express.js
Express.js is a web framework that uses Node.js; it is a minimalist web framework "micro-framework" that receives requests and replies with responses, micro-framework means it doesn't have ORM, template engine, etc. You can feel it is like Python Flask Framework.
ORM
I tried to build my models using sequelize JS as I'm more familiar with PostgreSQL DB engine, but it turns to be so tricky to implement my feature using RDBMS system. I switched ORM to Mongoose JS, and my database engine to MongoDB. I was wrong from the beginning, but after switching to MongoDB, it is much easier to implement the feature, as it is a preferred database engine in Node.js community.
Asynchronous Programming ๐ค
Getting used to the nature of JavaScript asynchronous "Promises" was a big challenge for me, I'm used to synchronous programming; thus it was a big paradigm shift ๐คฏ. On a daily basis, I'm using Django, and it is not asynchronous by default "there is a roadmap for Django to be Async". Python has asynchronous programming since version 3.5, but frameworks need to adapt it to become asynchronous as well, like requests-future.
Final Thoughts ๐ง
I enjoyed using Node.js; the community is excellent, there is nothing you can't find a package for on NPM, it is such an active community, but what I don't like in the community is the quality of tutorials, most of the tutorials targeting starters or naive nodejs developers, yes we need tutorials for starters and naive nodejs developers, but what about the advanced tutorials.
The async programming challenge was an eye-opener for me; I need to dig deep in this way of programming especially in Python. I'm lucky that there is a video course on Talk Python training about asynchronous in Python, and I think I will watch it.
Top comments (3)
Hello, it's interesting that JavaScript brings peoples into async programming in a fashion way (because it's everywhere, you need to do it).
I'm doing the opposite, learning python (working on data) from node background (web).
Have fun!
async programming always was in python try to check twisted and tornado
Thanks for your comment, you are right it was always there, but not in the standard library.