0

I'm recently been exploring node.js and I'm still confused of why require works one way and not the other.

Version of node: 0.12.5

Goal: format date time using strftime package

What works:

var strftime = require('strftime');

function time(){
    var d = new Date();
    return strftime('%Y-%m-%d: %H:%M', d); 
}

What does not work:

var strftime = require('strftime');

function time(){
    var d = new Date();
    d.strftime('%Y-%m-%d: %H:%M'); 
}

Throws and error stating that strftime is undefined.Can someone explain why? strftime API shows that the second method is a valid example.

Anna
  • 37
  • 3
  • 5

1 Answers1

0

You are reading the wrong docs. When you run:

npm install strftime

You're actually getting this library, not the one you're linking.

cviejo
  • 4,388
  • 19
  • 30
  • On a side note, extending native objects is at the very least [a controversial matter](http://stackoverflow.com/questions/14034180/why-is-extending-native-objects-a-bad-practice) which is probably one of the reasons why the syntax is not present in the newer library. I would've gone with the first example anyway. – cviejo Jan 15 '16 at 00:13
  • Thanks for the clarification – Anna Jul 11 '16 at 21:16