by
82k 37
4
8
22k
97
Top 1% !
Famous
Pearl of Wisdom
Nice
Tagged
Easy-to-find
Specified
OpenSource
Popularity: 122nd place

Published on:

Frameworknode.js
Languagetypescript
LicenseMIT_X11

Using moment.js in node.js with Typescript

You can easily install the moment.js library in node by using the command (on Mac):

> npm install moment

After that you need to download its type definition from Git/DefinitelyTyped:
https://github.com/borisyankov/DefinitelyTyped/tree/master/moment

To make it work, however you need to add the following to the moment.d.ts :
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/28686/Using-moment-js-in-node-js-with-Typescri?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// add this at the end of moment.d.ts to export the moment symbol declare module "moment" { export = moment; } // After that in your Typescript file you can use import import moment = require("moment");
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus