Learning to build
Let’s get the obvious comparison between Node.js and just about every other programming language out of the way to start. Node.js allows you to code in JavaScript on both the client (in the browser) and the server. This is a serious advantage for Node.js that’s difficult to replicate in other languages. JavaScript is the primary language of the web browser, so you’ll be writing client-side code in JavaScript or a language like it. Coding your app’s server in JavaScript simplifies your learning experience and unlocks the ability to share some code between the client and server. Sharing that code between the client and server can help you manage the complexity of your codebase and app.
Recent years have brought forward projects in Python that compile to JavaScript, aiming to provide this same flexibility to Python developers. One example is Transcrypt, which is actively developed. Young developers should be wary of jumping straight into a program like this while they’re learning. Learn to write standard JavaScript before writing code that will be compiled to JavaScript so you can spot common errors and learn to troubleshoot issues in your client-side code.
Scoreboard: Node.js 1, Python 0
Installing Node.js is a simple task, whether you use macOS, Windows, or Linux. For most users, it’s as simple as downloading an executable and double-clicking.
Installing Python is often more difficult. Python 2 comes pre-installed on macOS, but you shouldn’t use the installed version for your coding because it’s used by system libraries. Instead, you’ll need to install a new version alongside the existing version. Installing Python on Windowscan also be somewhat tricky. Many tutorials recommend installing a package manager like Chocolatey before getting started, which can be a bit of extra work. If you’re working on Linux, installing Python is no sweat.
Node.js is easier to use out of the box on two out of three platforms, so it scores another point here.
Scoreboard: Node.js 2, Python 0
Library management is a category in which both languages excel. Pip (which stands for “Pip installs Python”) provides tremendous library management for Python. The maintainers of Pip make sure that it’s fast, stable, and easy to learn in just a few minutes.
NPM (the Node Package Manager) provides package management for Node.js. NPM is one of the largest repositories of software libraries in the world. Like Pip, NPM is fast, well-documented, and a breeze to learn in an afternoon or less.
As your project grows, dependency counts usually grow as well. A good dependency manager saves hours of time and countless headaches.NPM and Pip are two of the best. Both languages score a point in this category.
Scoreboard: Node.js 3, Python 1
If you only ever work on one project, environment management isn’t a concern. Most developers find that between work and personal projects, they need to support more than one code repository. When working with a package manager like Pip or NPM, managing more than one codebase can cause serious headaches. What if the version of a library you use for work is different from the version of a library that you use for your personal website? This is where environment managers come into play.
The lead environment manager for Python is virtualenv. Virtualenv is a powerful tool that can manage different Python projects, up to and including installing different versions of the Python interpreter itself. Virtualenv is one of the original environment managers, and it’s been actively maintained for more than a decade. As you’d expect, it’s rock-solid and very easy to learn.
Node.js has a similar tool to Virtualenv called nodeenv. Nodeenv is developed and supported by the same people who make Pip, which is a great recommendation for a software package. Nodeenv comes with a big caveat, though: you need to install Python to make it work. If you’re deciding on Node.js to avoid having to install Python on your computer, using nodeenv would defeat the whole purpose.
Scoreboard: Node.js 3, Python 2
On the surface, both JavaScript and Python are similarly structured. Both are imperative languages with object-oriented features. Both have terrific IDE support. Python has a barer syntax than JavaScript; the lack of curly braces around classes or functions stands out to most new developers. Python is also whitespace sensitive, meaning that how you indent your code matters. Whitespace sensitivity is a double-edged sword for newer developers. Making sure that your code is always well-indented and organized is an important skill to learn for a new developer, and Python requires you to do that. The dangerous side is that improperly indented code can easily break for no obvious reason, and as a new developer, troubleshooting an issue like this is challenging.
While JavaScript’s syntax is likely to be familiar to many inexperienced developers, Node.js introduces additional advanced topics. Node.js web apps are written in what’s known as an asynchronous, event-driven style, which can be difficult to wrap your head around at first. A new developer learning Node.js has a tall hill to climb to understand advanced concepts like why a call to the database might not have information when the developer expects it to. The event-driven architecture is a very powerful performance boost (we’ll talk about why in the next section), but it poses a real challenge for newer developers.
Additionally, JavaScript has a notoriously thin standard library. NPM is popular in the JavaScript landscape because many things that are standard in other programming languages aren’t included in a normal install of JavaScript. As a new developer, this poses a challenge. You’ll commonly be faced with tasks that are simple in other languages but have no similar tool in JavaScript. Python edges JavaScript slightly here, so it wins a point.
Scoreboard: Node.js 3, Python 3
Asking which programming language is faster is a dangerous exercise on the internet! In this comparison, you’ll find little dissension, though. Node.js web apps are mostly faster than Python web apps. The reason is related to that event-driven architecture we talked about in the last section. If you haven’t read the link in the previous section (here it is again so you don’t have to scroll back), you should do that now to truly understand why. Node.js code doesn’t spend as much time waiting on network requests and database queries. This means that it does more work in less time, which means faster server responses and page renders.
Python does have the ability to build asynchronous, event-driven web apps. Modules like asyncio make writing asynchronous Python code similar to writing that kind of code in Node.js. Python doesn’t win a point here, though, because most major Python frameworks don’t have this built in.
Another performance advantage for Node.js is that it runs on the V8 JavaScript engine, which is the same engine used in the Chrome web browser. Google devotes a large number of developers to making V8 as fast as possible, which is good news for Node devs. Node.js is likely to continue to get faster over the next few years. Your web app could be faster in a year without you changing a single line of code! Node.js also has powerful tuning capabilities that boost your already good performance to another level.
Finally, it’s important to remember that just because you choose one language or framework, you’re not guaranteed a fast web app. Monitoring the real-world performance of your app through a tool like Retrace is critical to understanding how your app is actually performing for your users.
Scoreboard: Node.js 4, Python 3
Looking at the scoreboard, Node.js holds a slight lead over Python, and I think that’s accurate. In 2019, both Node.js and Python are attractive options for building a new web app. As someone who’s just learning, you may find that Node.js has a pile of excellent frameworks to choose from. Python has similarly excellent frameworks in Django and Flask. Neither choice is a wrong one, and both languages have thriving communities. If it were up to me to choose which language I’d use to start a new web project, I would lean toward Node.js. But the most important thing is to start turning your dream web app into reality today. Get out there and get coding!
If you would like to be a guest contributor to the Stackify blog please reach out to [email protected]