An introduction to Web Development with Rust for Node.js Developers

An introduction to Web Development with Rust for Node.js Developers

What is Rust and why do I want 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.

What is Rust and why do I want 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.

Rust is different. You can pick up Python or Ruby over the weekend, create a first CRUD application and be happy with the results.

With Rust… with Rust you will struggle to pass a String to a different method, change and return it. You then will order the Rust book, see its size, sigh and get started.

After a few weeks of fighting through the book after work, you give up and wait until someone else creates an easy-to-follow tutorial.

Here is your “easy” tutorial

I struggled with the same problems. Life circumstances however gave me a few months time on my hands to really focus on Rust.

What follows is a first overview, concept, and paths to follow. In the coming weeks and months, I’ll publish a series of articles to help you to get from concept to product.

NodeJS vs Rust

After installing them (I chose brew for macOS in this example, the method doesn’t matter), the underlying stack looks different. NodeJS needs V8, the runtime engine from Google, and bindings to the JavaScript library to run JavaScript code.

Rust depends almost completely on Rust itself. Just the compiler is using llvm libraries, which are written in C and C++.

How much “web” is in Rust?

It was and is a design decision not to include a standard http library in Rust. The OSI layer is therefore covered differently:

Node covers the whole stack, and offers with Koa and Express, two well-known and “rock-solid” web frameworks which help you to build applications on top of HTTP.

On the Rust side of things, just TCP is implemented in the Rust Core. The current web frameworks (actix and rocket) are implementing everything up until HTTP though. So you don’t need to care where this is coming from.

If you want to use pure HTTP calls without any larger framework, you can install “crates” (equivalent to npm packages in the Node world) which implement the HTTP protocol (like hyper and tiny_http).

npm vs cargo

Node is using npm for its package management:

  • npm install is installing dependencies
  • npm run xyz is executing scripts inside the package.json

On the Rust side, cargo is handling everything related to your project:

  • npm install is installing dependencies
  • npm run xyz is executing scripts inside the package.json

There is an open PR to add cargo add to install dependencies. Right now you have to add them by hand to your Cargo.toml file. As you see, you don’t need to include scripts in a package.json to run tests or build and test your application.

Mindset change: Cargo is fetching the packages after cargo run, and just if the version changed. So the first time it will fetch all packages, the second time just when a change in the version number happened. Unlike npm i which fetches the packages right away, and will add it to the package.json with the save notation.### Ecosystem

Node is not successful for no reason. The ecosystem is rich and flourishing. Rust is still developing, but has already many great “crates”. The website arewewebyet.org is tracking the progress and showing you interesting packages in the Rust world.

There is also an attempt to create an official Rust Web Framework, called Tide. It is already pretty mature and can be used for side projects. Feel free to contribute and help craft a great environment for web development in Rust.

Asnyc programming aka Promises aka Futures

Nodes killer feature are Promises. Although not always easy to understand and handle, Promises and the event loop are what makes Node so lucrative.

Rust is also implementing an asynchronous mechanism, which are not yet in the final version. They are called Futures. A library called Tokio is already offering an asynchronous run time. You can track the progress on asynchronous programming in Rust over at areweasyncyet.

How to get started?

  1. Install Rust: curl [https://sh.rustup.rs](https://sh.rustup.rs "https://sh.rustup.rs") -sSf | sh
  2. Create a new project: cargo new web-app --bin
  3. cd web-app

Now you can choose your web framework of choice. You can either start with rocket or actix. You can follow the tutorials on the website to get a first web application running.

Heads up: undefined, borrowing and types

To not to get frustrated until my next post, here are the main four things about Rust you will have to get used to (which are quite awesome after a while).

  1. Install Rust: curl [https://sh.rustup.rs](https://sh.rustup.rs "https://sh.rustup.rs") -sSf | sh
  2. Create a new project: cargo new web-app --bin
  3. cd web-app

Use this example to play around, see where you can get errors and learn to fix them.

Is this all?

Two opinions:

  • npm install is installing dependencies
  • npm run xyz is executing scripts inside the package.json

You actually have to learn a decent amount of Rust to get started. This is what I am here for. In the next few days, weeks and months I will cover the basics up until creating a solid web application.

Top Vue.js Developers in USA

Top Vue.js Developers in USA

Vue.js is an extensively popular JavaScript framework with which you can create powerful as well as interactive interfaces. Vue.js is the best framework when it comes to building a single web and mobile apps.

We, at HireFullStackDeveloperIndia, implement the right strategic approach to offer a wide variety through customized Vue.js development services to suit your requirements at most competitive prices.

Vue.js is an open-source JavaScript framework that is incredibly progressive and adoptive and majorly used to build a breathtaking user interface. Vue.js is efficient to create advanced web page applications.

Vue.js gets its strength from the flexible JavaScript library to build an enthralling user interface. As the core of Vue.js is concentrated which provides a variety of interactive components for the web and gives real-time implementation. It gives freedom to developers by giving fluidity and eases the integration process with existing projects and other libraries that enables to structure of a highly customizable application.

Vue.js is a scalable framework with a robust in-build stack that can extend itself to operate apps of any proportion. Moreover, vue.js is the best framework to seamlessly create astonishing single-page applications.

Our Vue.js developers have gained tremendous expertise by delivering services to clients worldwide over multiple industries in the area of front-end development. Our adept developers are experts in Vue development and can provide the best value-added user interfaces and web apps.

We assure our clients to have a prime user interface that reaches end-users and target the audience with the exceptional user experience across a variety of devices and platforms. Our expert team of developers serves your business to move ahead on the path of success, where your enterprise can have an advantage over others.

Here are some key benefits that you can avail when you decide to hire vue.js developers in USA from HireFullStackDeveloperIndia:

  • A team of Vue.js developers of your choice
  • 100% guaranteed client satisfaction
  • Integrity and Transparency
  • Free no-obligation quote
  • Portal development solutions
  • Interactive Dashboards over a wide array of devices
  • Vue.js music and video streaming apps
  • Flexible engagement model
  • A free project manager with your team
  • 24*7 communication with your preferred means

If you are looking to hire React Native developers in USA, then choosing HireFullStackDeveloperIndia would be the best as we offer some of the best talents when it comes to Vue.js.

Learn Node.js - Node.js API Development for Beginners

Learn Node.js API Development from absolute scratch. This video is for complete beginners getting started guide!

In this video you will learn the core fundamentals of Node JS so that you can start building API using Node JS. You will learn Modern JavaScript, Node JS event loop, Asynchronous programming, using node modules, npm modules and creating your own modules, creating server, connect to database and sending json responses.


Learn More

Node.js With Passport Authentication | Full Project

Full Stack Developers: Everything You Need to Know

MEAN Stack Tutorial MongoDB, ExpressJS, AngularJS and NodeJS

How to Perform Web-Scraping using Node.js

Moving from NodeJS to Go

Authenticate a Node ES6 API with JSON Web Tokens

The Complete Node.js Developer Course (3rd Edition)

Angular & NodeJS - The MEAN Stack Guide

NodeJS - The Complete Guide (incl. MVC, REST APIs, GraphQL)

Node.js: The Complete Guide to Build RESTful APIs (2018)