I'm trying to run this simple file in an empty folder
// time.js
const moment = require('moment')
function getDay() {
var today = moment().day()
console.log(today);
}
getDay()
using node time.js
But I get
Error: Cannot find module 'moment'
However I have run npm install -g moment and npm install moment.
What noob error am I doing?
Just do the following commands on your console inside your folder:
npm init // just hit enter some times or follow the process
npm install moment --save
node time.js
Note: You could skip the npm init part but I wouldn't recommend it due to dependency control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With