Building a REST API With Node.js Express and MongoDB

In this post, we will build a RESTful API server from scratch with Node.js. We will use the Express library as the application server and MongoDB as the database. Architecture Overview As an example, we’ll build an inventory manager application. Using our API we will be able to create new items, list down their stock, and add or remove items from the stock when they’re purchased or replenished. Let’s look at the different components of this application:...

How to Execute Shell Commands With Node.Js

This tutorial will teach you how to execute shell commands, and even your own custom shell scripts with Node.js. We will learn how to create a program in Node.js to run common commands like ls, mkdir or even npm on your Unix system (Mac or Linux). If you just want to see the code, you can view it on Github The Child Process Module When we execute shell commands, we are running code outside of our Node....

Session Cookie Authentication in Node.js (With Complete Examples)

In this post, we will learn how to authenticate users using session cookies in a Node.js server application. When a user logs into our application, we need to know who they are across all our HTTP methods and routes. One way to do this is to store the users “session”. A session is started once a user logs in, and expires some time after that. Each logged in user has some reference to the session (called a cookie), which they send with their requests....

A Complete Guide to HTTP/2 in Node.js (With Example Code)

This post will explain what HTTP/2 is, and how we can make use of its features in Node.js. HTTP/2 is the next version of the Hyper Text Transport Protocol (HTTP), which adds many features and optimizations over the previous version. In the next few sections, we will understand these features in detail, and also learn how to implement them as a client and server using the Node.js http2 standard library....

Implementing a Kafka Producer and Consumer In Node.js (With Full Examples) For Production

In this post we will learn how to create a Kafka producer and consumer in Node.js. We will also look at how to tune some configuration options to make our application production-ready. Kafka is an open-source event streaming platform, used for publishing and processing events at high-throughput. There are a lot of popular libraries for Node.js in order to interface with Kafka. For this post, we will be using the kafkajs library (but the same concepts will apply for any other library as well)....

A Guide On SQL Database Transactions In Node.js

This article explains what SQL database transactions are, and how to implement them in Node.js. SQL Transactions are very useful when you want to perform multiple operations on a database, but still treat them as a single unit. We will go into detail on why this is useful, and how you can use it in your Node.js applications. To illustrate our examples, we will use Postgres as our database of choice....

RSA Encryption, Decryption and Signing in Node.js (Javascript) - With Examples

This post will explain the RSA algorithm, and how we can implement RSA Encryption, Decryption and Signing in Node.js using its standard library. RSA (Rivest–Shamir–Adleman) encryption is one of the most widely used algorithms for secure data encryption. It is an asymmetric encryption algorithm, which is just another way to say “one-way”. In this case, it’s easy for anyone to encrypt a piece of data, but only possible for someone with the correct “key” to decrypt it....

Making a Testing Framework in Node.js (Without any External Libraries)

If you’ve ever written tests for a Node.js application, chances are you used an external library. However, you don’t need a library to run unit tests in Javascript. This post is going to illustrate how to make your own simple testing framework using nothing but the standard library. It’s actually much simpler than you may think. If you want to skip the explanation and just see the code, you can find it here...

Node.js File System Module - How to Read and Write Files and Directories

The Node.js fs module enables us to work with the file system, which is one of the most fundamental tasks when writing programs. However, there are several ways in which we can interact with the file system using the fs module, and each method has its trade-offs. This post will explain how to use the file system module to read and write files and directories using sync, async, and streaming APIs....

Last Updated:   · Written by Soham Kamani

Implementing JWT Authentication in Node.js

In this post, we will demonstrate how JWT(JSON Web Token) based authentication works, and how to build a sample application in Node.js to implement it. If you already know how JWT works, and just want to see the implementation, you can skip ahead, or see the source code on Github The JSON web token (JWT) allows you to authenticate your users in a stateless manner, without actually storing any information about them on the system itself (as opposed to session based authentication)....

Last Updated:   · Written by Soham Kamani