Let’s build a ToDo MERN app using GraphQL and Node.js, In this part, we will implement a backend service.
In this article, we will create a backend service with GraphQL i.e Apollo Server and MongoDB database.
We will be using the MongoDB
database so make sure you install it locally or you can use free cloud service from MongoDB.
By creating this App, you will learn
Create a new project using npm
npm init -y
This command will set the default value in package.json
…
The current version of Node.js added support for Top-Level Await just like Deno.js, and other languages like C#.
Now, It’s now possible to use the await keyword outside of async functions.
Let’s take a look at an example.
We will fetch a quote from API.
Download and Install Node.js v14.3.0
Create Node.js project using :
npm init — yes
Now install the Axios library for fetching data from API.
npm install axios --save
Now modify apackage.json
file.
Take a look here, we added type as module
. Because the language has not fully implemented it yet stage 3.
Code goes like this,
Running this file using node --harmony-top-level-await top-level-async-await.js
.
In this blog, we will create a thread for CPU extensive tasks that not blocking the main event loop.
As we know, Node.js is a JavaScript runtime environment and runs the V8 JavaScript engine, the core of Google Chrome, outside of the browser.
A Node.js app is run in a single process and JavaScript doesn’t support threading, then How we can do CPU extensive and long-running tasks without blocking the main event loop?
Is it really Node.js single-threaded?
Not really, Your JavaScript is not support threading but not Node.js, Node.js internally uses C++, recent addition of Node.js …
In this blog, we will learn to implement reverse proxy for NodeJS server
Proxy is the server that sits in between a client and an actual server.
In this blog, we will learn to build COVID19 SMS Tracker using external API and Twilio.
Let’s get started,
Install the required packages
npm install --save express twilio axios
We will be using an external REST API to get COVID19 Cases.
First, get the latest COVID19 cases for India using Axios.
const covidINdata = await axios.get('https://api.covid19api.com/live/country/india/status/confirmed');const latestData = covidINdata.data;//API returns array which contains all snapshots of cases. We will use latest, means last element of array.
const data = latestData[latestData.length - 1];
Now configure, Twilio SMS API
Signup for Twilio, and get Account ID and API KEY.
const ACCOUNT_ID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const API_KEY =…
Redis is an in-memory data structure used for cache. In this blog, we will implement a simple NodeJS app that uses Redis.
Redis is an open-source, in-memory data structure store, used as a NoSQL database for the cache to improve the overall response rate for most frequently requested data.
In this blog, we will develop Notes Taking App API, We will implement two feature,
But here will use Redis, to cache note. If the user requests the same note frequently, we will return note stored in Redis.
REST API…
In this tutorial, We will learn to protect REST APIs using JSON Web Token with an example.
JSON Web Token (JWT) is way of authenticating user on internet. As name suggest it is JSON based taken. The token is signed using private secret key or public key. For example, a server could generate token which user login and provide to the client. This token could signed using user_id or email with secret key and expiration timestamp. This token payload used when client need to authenticate on server.
JWT is mostly useful for REST APIs, mobile apps, Single Page Web Apps, etc. …
OS module provides information related to the operating system and hardware.
The os
module provides API for getting information about hardware related like CPU, memory, directories, IP address and many more.
In this tutorial, we will learn basics methods and some more concepts of os
module.
To start working with the os
module, we have to import os
module in our project.
const os = require('os);
This method will return the architecture of the processor.
const os = require('os');console.log(os.arch());
Output:
x64
This method returns an array of the object which contains information of logical CPUs.
const os = require('os);console.log(os.cpus());
Output…
The fs
module provides us API to interact with the File System of the operating system (Server).
The fs
module provides API for interacting with the file system of the operating system. All file operations may synchronous or asynchronous I/O operations. Asynchronous methods take the fist parameter as error and the last parameter as a callback.
In this tutorial, we will learn basics operations and some more concepts of fs
module.
To start working with the file system, we have to import fs
module in our project.
const fs =…
In this article, we will look at how to design REST APIs to be easily understandable.
REST is an acronym for REpresentational State Transfer. It is an architectural style for distributed hypermedia systems and was first presented by Roy Fielding in 2000.
REST APIs are one of the most commonly used web services in the modern world. They allow browsers, mobile apps to communicate with the server.
That’s why the proper design of REST APIs is important. Proper design help to scale, manage our backend services. Otherwise, we create problems for clients that use our APIs.
We will discuss some common design examples. We will be using the NodeJS and ExpressJS framework for this tutorial. …