Rust for Node developers

Rust for Node developers

An introduction to the Rust programming language for Node developers.

Hi there, I'm a JavaScript developer who wants to learn Rust and as a part of this process I'll write here about my learnings. So what is Rust actually and why should you learn it ? It is a systems programming language like C or C++, but with influences from functional programming languages and even scripting languages like JavaScript. It feels very modern - which is no surprise, because it is a relatively young language. It went 1.0 in 2015! That doesn't only mean it is fun to write , because it has less clutter to carry around, it is also fun to use , because it has a modern toolchain with a great package manager. Rust's most unique feature is probably the compile-time safety check: it catches errors like segfaults without introducing a garbage collector. Or to phrase it differently: maximum safety with maximum performance.

Probably even more important than its features is the ecosystem and the community behind a language. Rust really shines here - especially for people who love the web. It is baked by Mozilla and the biggest real world project written in Rust is probablyservo, a modern browser engine. servo is actually very modular - e.g. you can require its HTML parser as a standalone module . Can you do that with any other browser engine? As far as I know... no . Chances are pretty high that Rust will become a good host platform forwasm - the future binary format for the web.

Before we dive into our setup we want to look at least once into a real Rust file:

fn main() {
    println!("Hello World!");

The JavaScript equivalent could roughly look like this:

function main() {
  console.log('Hello World!');

Nothing too scary, right? The ! behind println could be a bit confusing, but don't mind it for now. Just think of it as a special function.

How do we move on from here? First I'll guide you how my current setup looks like to use Node and Rust. After that I'll create several kitchen sink like examples - first with Node and then with Rust. I'll try to explain them as best as I can, but don't expect in-depth explanations in every case. Don't forget that I'm trying to learn Rust - just like you . Probably you need to explain me some things, too! Oh, and before I forget it: my Node examples will be written in TypeScript actually! I think it makes some examples easier to compare to Rust and if you experience sweet code completion for Rust you want a little bit of that in your Node projects anyway ;)

Table of contents

  1. Setup
  2. Hello World
  3. Package Manager
  4. Read files

Thank you for reading this article. ♥