Join 10350+ others. No spamming.
I promise!

Follow us at github.



Mercateo / rust-for-node-developers


An introduction to the Rust programming language 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? Rust 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 the language. Rust really shines here - especially for people who love the web. It is backed by Mozilla and the biggest real world project written in Rust is probably servo, a modern browser engine. servo is 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 for wasm - 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 type safety from Rust you want a little bit of that in your Node projects anyway ;)

I try to add an example every two weeks.

Table of contents

  1. Setup
  2. Hello World
  3. Package Manager
  4. Read files
  5. Write files
  6. HTTP requests
  7. Parse JSON

Thank you for reading this article. ♥

I highly appreciate pull requests for grammar and spelling fixes as I'm not a native speaker. Thank you!