Moment.js using with Require.js Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Require.js is a library that is used to load JavaScript files and modules. It is used to improve the speed and quality of your code. We can use Moment.js with Require.js support. Installation in Node.js: npm install moment npm install requirejs Steps for using Require.js in Node.js: Go to any convenient location on your computer and create a new directory named moment-require.Open a terminal and type the command:npm init -yNow, open a code editor in the current project directory.Edit the package.json as shown in the figure below: Now, create a new file named index.js in the current directory.Now, import the requirejs module into your project:var requirejs = require('requirejs');Pass the index.js file's "require" function in the configuration to requirejs.requirejs.config({ nodeRequire: require, baseUrl: __dirname });Now, load a moment.js using require.js as shown in the code below:var moment=requirejs('moment');Create a new date object using the code below:var dateNow = Date.now(); //Current date object Now, use the moment to format the date using the code below:var formattedDate = moment(dateNow).format('LLL'); //pass the date object to moment function.Print the date into the console using:console.log (formattedDate); // December 19, 2022 10:47 PM Example 1: JavaScript const requirejs = require('requirejs'); requirejs.config({ nodeRequire: require, baseUrl: __dirname }); let moment = requirejs('moment'); let dateNow = Date.now(); let formattedDate = moment(dateNow).format('LLL'); console.log(dateNow, formattedDate); Output: December 19, 2022 10:47 PM Example 2: JavaScript const requirejs = require('requirejs'); requirejs.config({ nodeRequire: require, baseUrl: __dirname }); let moment = requirejs('moment'); let dateNow = "2010-10-20 04:30"; let formattedDate = moment(dateNow, 'YYYY-MM-DD H:mm') .format('LLL'); console.log(formattedDate); Output: October 20, 2010 4:30 AM Reference: https://momentjs.com/docs/#/use-it/require-js/ Comment More infoAdvertise with us Next Article Moment.js using with Other A aaloksah766626 Follow Improve Article Tags : Technical Scripter Web Technologies Node.js Technical Scripter 2022 Similar Reads Moment.js using with Node.js Moment.js simplifies date manipulation in Node.js by providing a powerful library for parsing, validating, manipulating, and formatting dates. It enhances handling time related operations, making complex date tasks straightforward and efficient. In this article, we are going to see how we can use mo 2 min read Moment.js using with System.js Moment.js is a popular JavaScript library for working with dates and times. It provides a simple and powerful API for parsing, validating, manipulating, and formatting dates and times. System.js is a dynamic module loader for JavaScript, which allows you to import and load modules as needed at runti 3 min read Moment.js using with Other Moment.js is a JavaScript library for parsing, validating, manipulating, and formatting dates and times. It is widely used by developers for its simplicity and robustness, and it is considered one of the most popular libraries for date and time-related operations. Moment.js is open-source and availa 4 min read Moment.js using with NuGet Moment.js is a powerful JavaScript library that simplifies working with dates and times in web applications. It provides an intuitive and straightforward interface for manipulating dates and times, allowing developers to easily format and parse dates and times, perform calculations and comparisons, 4 min read Moment.js using with Bower Moment.js is a popular JavaScript library used for parsing, validating, manipulating, and formatting dates. It is a lightweight library that makes it easy to work with dates and times in JavaScript. Bower is a package manager for the web and is used to manage packages and dependencies. It is a great 2 min read Moment.js using with Typescript In this article, we will learn how to use the Moment.js library with Typescript language. Typescript is a strongly-typed programming language that wraps JavaScript and gives it optional static typing. It is free and open source and is maintained by Microsoft. Using Moment.js with Typescript: To use 1 min read Like