paint-brush
Why you should choose date-fns over moment.js in your nodeJs applicationsby@_bengarrison
10,525 reads
10,525 reads

Why you should choose date-fns over moment.js in your nodeJs applications

by Ben GarrisonMarch 2nd, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

It’s simple: Targeted Module Imports

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Why you should choose date-fns over moment.js in your nodeJs applications
Ben Garrison HackerNoon profile picture

It’s simple: Targeted Module Imports

Link up:


Modern JavaScript Date Utility Library_date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a…_date-fns.org


Moment.js | Docs_define(['moment'], console.log(moment().format('LLLL')); }); define(['moment', 'moment/locale/de']…_momentjs.com

The Javascript Date object has problems, here is some reading on the subject:

Emphasizing the problems is the growing number of JS Date wrapper libraries aimed at solving problems and simplifying manipulation of dates in your code. The clear winner up to this point(and my personal go-to) has been Moment.js. Moment is great and offers almost all of the features that I am looking for.

Recently, I began work on a new NodeJs project at work, and webpack bundle size is of high importance to us at the moment. The micro-service that I have been working on in-particular requires some specific Date validation and manipulation that I have previously gone to Moment.js for. But then, I discovered that Moment.js does not have the ability to import specific modules, it’s all or nothing. So, I googled for alternatives and found this:

So I checked it out, I decided to import and let it have a chance. I imported what ended up being 4 specific functions to get the job done. Those 4 functions cost me almost nothing.

I am a week in and still using it. Curious to know if anybody else out there is using date-fns. As I am writing this I decided to go find out and yeah, peeps are using it. To the tune on 2MIL+ npm downloads in the last month at the time of this writing:


date-fns_Modern JavaScript date utility library_www.npmjs.com

What are your thoughts on date-fns in NodeJs projects? Is there something better? Let me know your thoughts and questions and give me a follow on twitter. Keep after it.

If you like this article, please recommend and share to help others find it!