1st Class SpreadTechAfrica-Backend Track

Chiboy
6 min readApr 13, 2024

--

Introduction to backend development using nodejs

Backend development is like the engine of a car. While the front-end (like the steering wheel and dashboard) is what users interact with directly, the backend is where the magic happens behind the scenes. In this note, we’ll explore what backend development is all about and how we can use Node.js to build powerful and dynamic web applications.

What is Backend Development?

Backend development involves writing code that runs on the server and is responsible for handling tasks such as data storage, retrieval, and processing. It’s like the brain of a web application, managing everything that happens behind the scenes.

Backend development is a crucial aspect of software engineering that focuses on building the logic and functionality that powers applications. By understanding how backend development works and its functions in software engineering, developers can create robust, scalable, and secure software solutions that meet the needs of users and businesses alike.

History of Nodejs

Node.js was created in 2009 by Ryan Dahl. Previously, Dahl had criticized the limited possibilities offered by existing popular web servers and common coding methods.

At the time, servers struggled to handle high-volume concurrent connections, and codes either blocked the entire process or implied the need for multiple stacks. These were all issues that hampered the ability of businesses to build versatile products that engaged with and met high-volume user requirements.

In response, Dahl created Node.js to provide developers with the power to use JavaScript for server-side scripting and unifying web application development around a single programming language.

The initial release of Node.js only supported Linux and Mac OS X operating systems. Its development and maintenance was led by Dahl at first, and later sponsored by Joyent, a software and services company.

In January 2010, a package manager for Node.js was introduced to make it easier for programmers to publish and share source code of Node.js packages and simplify installation, uninstallation and updates.

In 2011, Microsoft and Joyent came together to develop a native Windows version of Node.js, expanding the number of operating systems it could support and giving developers more options than ever.

Since then, a neutral Node.js Foundation has been formed to bring developers together in one community. The Node.js foundation was merged with the JS Foundation in 2019, to form the OpenJS Foundation. The foundations help to govern the open-source, distributed development project of Node.js.

NodeJs Architecture

The mechanics of Node.js are what contributes to its popularity with developers. Whereas most alternative runtime environments utilize multi-threaded processing models, Node.js does it all in a single thread.

In multi-threaded processing setups, each server has a limited thread pool it can access. So every time a server receives a request, it pulls a thread from the pool and assigns it to that request, to take care of processing it. In this case, the processing is synchronous and sequential, which means that one operation is performed at a time.

In multiple-thread processing, a thread is picked out every time a request is made until all of the limited threads are used up. When this happens, the server has to wait for a busy thread to become free again. This can make for slow and inefficient applications, which leads to knock-on effects on anything from customer experience to lead conversions. It can particularly become a problem if your application has to deal with a high number of concurrent client requests.

Node.js, however, uses single-threaded processing. The difference between the two is as you’d imagine: single-thread architectures process every request using a single main thread, utilizing event loops to run blocking Input/Output operations in a non-blocking way.

A single-thread architecture can, in theory, perform and scale much more quickly and efficiently than multiple-thread setups. This is what Ryan Dahl had in mind when he first wrote Node.js and is a big part of why it is so popular among web application developers.

Why Should you use Node.js

Some of the benefits of Node.js are as follows:

1. Easy to Learn

Javascript is one of the most popular programming languages for front-end development, and nearly every front-end developer is familiar with this universal language.

Therefore, it is much easier for developers to switch to using Node.js at the back-end. It requires less effort and less time to learn and work with, even for a junior Javascript programmer.

2. Freedom in app development

While Ruby on Rails is a framework that imposes rules and guidelines for developing software in a particular way, Node.js offers more space and freedom for doing things your own way

Node.js is completely un-opinionated, meaning you can build everything from scratch and tailor every last detail. It can execute basic tasks, but gives you only the bare minimum from a fresh install, allowing you to add features from there with less restrictions.

3. Fullstack JS

Before Node.js, the JavaScript code was only used for client-side development. It was necessary to use a different server-side programming language. In practice, you had to hire separate development teams for backend and frontend.

With Node.js growing in popularity, fullstack JavaScript became a reality. Nowadays it is possible to write both the front-end and back-end of web applications in Javascript, making app deployment much easier and more efficient.

4. Active community

The Node.js developers community is an active and vibrant group of developers who contribute to constant improvement of Node.js. Thanks to the cooperation of JavaScript programmers and their input to the community you get access to a ton of ready solutions, codes in Github and many more possibilities.

Even though it is still at a relatively early stage of development, the community is evolving dynamically and its members go the extra mile to provide others with best-in-class, reliable solutions.

5. Simultaneous Request Handling

Node.js provides a non-blocking I/O system that lets you process numerous requests concurrently. Incoming requests are queued up and executed sequentially in rapid time. In effect, your app will take up much less system RAM, achieve high scalability levels and will perform faster as a result.

Node package manager

Node package manager (or ‘npm’ for short) does a few things; firstly, it acts as an online repository for publishing open-source Node.js projects. Secondly, it is used as a command-line facility for interacting with that repository, assisting with package installation, version management and dependency management.

It is used most commonly to publish, discover, install and develop Node programs. Essentially, it helps developers to make best use of Node.js tools and packages with a useful interface.

Source: https://www.netguru.com/glossary/node-js#introduction

Practical Section

Installation of Vscode: https://www.youtube.com/watch?v=CPmQwlycfGI

Installation of Nodejs: https://www.youtube.com/watch?v=J8ZPZq_34aY

Now that we have nodejs installed, let’s create our first nodejs project

Lets create a simple express application with a GET METHOD

  1. Go to https://www.npmjs.com/package/express and copy npm i express
  2. Open your terminal in vscode and paste npm i express then click enter to install the express package
  3. After a successful installation, create a file app.js which is going to be your entry file
  4. Next, paste this in the file to create a simple
const express = require('express');
const app = express();

app.get('/', function (req, res) {
res.send('My name is chiboy');
});


app.listen(3000, function() {
console.log(`Server is running at http://localhost:3000`)
});

Basically this is just a simple nodejs express application, that runs on port 3000

5. Next, go to your terminal and run node app.js to start the server. You should see this message on the terminal “Server is running at http://localhost:3000

6. Go to your browser and enter the Url http://localhost:3000, Since it’s a GET method you should see something like this:

If you encounter any challenges, feel free to drop a comment or reach out to any of the support in SpreadtechAfrica.

ASSIGNMENT: Get a github account and learn the basic github commands

use this link as a guide: https://www.youtube.com/watch?v=QUtk-Uuq9nE

--

--