Node.js | Moment Module

The moment module is used for parsing, validating, manipulating, and displaying dates and times in JavaScript.

Feature of moment module:

  1. It is easy to get started and easy to use.
  2. It is widely used and popular for formatting date and time.

Installation of moment module:

  1. You can visit the link to Install moment module. You can install this package by using this command.
    npm install moment
  2. After installing moment module, you can check your moment version in command prompt using the command.
    npm version moment
  3. After that, you can create a folder and add a file, for example index.js. To run this file, you need to run the following command.
    node index.js

Filename: index.js





var moment = require('moment');
// 2020-05-08T22:57:42+05:30
// May 8th 2020, 10:56:31 pm
console.log(moment().format('MMMM Do YYYY, h:mm:ss a'));
// Friday
// May 8th 20
console.log(moment().format("MMM Do YY"));
// 2020 escaped 2020 
console.log(moment().format('YYYY [escaped] YYYY'));


Steps to run the program:

  1. The project structure will look like this:
    project structure
  2. Make sure you have install moment module using the following commands:
    npm install moment
  3. Run index.js file using below command:
    node index.js

    Output of above command

So this is how you can use the moment module for parsing, validating, manipulating, and displaying dates and times in JavaScript.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :


Please write to us at to report any issue with the above content.