How to Get Current Day in Node.js?

05-Sep-2022

.

Admin

How to Get Current Day in Node.js?

Hi Dev,

This article will give you an example of how to get the current day in node.js. This article goes into detail on how to get the current day in nodejs. you can see node.js get the current day. I would like to show you nodejs get current day example. follow bellow step to get the current day in node.js.

In this tutorial, we learn to Get Current Day in Node js. I will use this example Date() and getDay(). to get current day. Date() function used to get current date and getDay() get current day. There are several ways to get the day in a granular manner from this class.

So, let's start following example with output:

Step 1: Create Node.js Project


This step is not required; however, if you have not created the node js app, then you may go ahead and execute the below command:

mkdir my-app

cd my-app

npm init

Step 2: Update index.js file

index.js

// create day array list

let daysArray = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

// get day use date function

let day = new Date().getDay();

// get day name

let dayName = daysArray[day];

console.log(dayName);

Output:

Monday

I hope it can help you...

#Node JS