Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use `moment.js` with Meteor?

I am wanting to use momentjs with meteor. This is an npm package, so from what I understand, it cannot be used with meteor because meteor uses it's own package system. So here are my questions:

  • Does anyone know of a way to use momentjs with meteor?
  • Is there a way to use npm packages with meteor?

2017 EDIT: As of Meteor 1.4+, npm package management allows for standard imports of npm modules and named imports of Atmosphere modules.

like image 730
Tyler Jones Avatar asked Feb 03 '13 02:02

Tyler Jones


People also ask

Is MomentJS deprecated?

Moment construction falls back to js Date. This is discouraged and will be removed in an upcoming major release. This deprecation warning is thrown when no known format is found for a date passed into the string constructor.

What is moment JS used for?

MomentJS is a JavaScript library which helps is parsing, validating, manipulating and displaying date/time in JavaScript in a very easy way. This chapter will provide an overview of MomentJS and discusses its features in detail. Moment JS allows displaying of date as per localization and in human readable format.

What can I use instead of moment in JavaScript?

There are several libraries out there that can potentially replace Moment in your app. The creators of Moment recommend looking into Luxon, Day. js, date-fns, js-Joda, or even replacing Moment with native JS.

Should you use moment JS?

Moment. js is a fantastic time & date library with lots of great features and utilities. However, if you are working on a performance sensitive web application, it might cause a huge performance overhead because of its complex APIs and large bundle size.


1 Answers

2017 UPDATE - Meteor 1.4+ uses npm modules with ES6. OP is from 2013.

Thus...

The npm-only way:

install moment to your meteor project with npm and import in this manner...

$ cd /path/to/my/meteor/project
$ npm install --save moment

// inside your Meteor app files...
import moment from 'moment';

The meteor-npm way with a blanket import: (Thx, @Dave Gööck)

$ cd /path/to/my/meteor/project
$ meteor npm install --save moment

// Inside Meteor app...
import * as moment from 'moment';
// OR
import moment from 'moment';

More about Meteor-npm package imports here. (Specifically mentions moment).

like image 107
4Z4T4R Avatar answered Oct 26 '22 02:10

4Z4T4R