Reference Error: moment is not defined (Using moment.js)

I installed the moment.js library and was about to play around with it a little bit, when i got this error. I’ve tried many different things, but nothing has worked. Any ideas?

I have a folder that i’ve installed moment.js into (npm install moment) and i’m running my program (node isDate.js).

import {moment} from 'moment';

function isDate(string) {
    {
        moment(string).format(["MM-DD-YYYY", "YYYY-MM-DD"]);
    }
} exports.isDate = isDate;

ReferenceError: moment is not defined

Leave a Comment