Search code examples
node.jsformidable

Javascript Object properties (in Node) not getting logged or logged with a different name


I am using Node's formidable package from felixge. This is more a Javascript question than one specific to formidable, or so I think.

If I do a console.log on MYOBJ, I get the following:

{ file1: 
  File {
   domain: null,
   _events: {},
   _eventsCount: 0,
   _maxListeners: undefined,
   size: 62464,
   path: 'myDir/upload_e79d8d551721e2f399afbc39d5d5eaab.doc',
   name: 'somefile.doc',
   type: 'application/msword',
   hash: null,
   lastModifiedDate: Thu May 19 2016 20:22:24 GMT+0530 (IST),
   _writeStream: 
    WriteStream {
      _writableState: [Object],
      writable: true,
      domain: null,
      _events: {},
      _eventsCount: 0,
      _maxListeners: undefined,
      path: 'uploadDir/upload_1e0e9625e27f5c5172eaf5d18172f946.doc',
      fd: null,
      flags: 'w',
      mode: 438,
      start: undefined,
      pos: undefined,
      bytesWritten: 62464,
      closed: true } } }

If I do a console.log, like so:

for (var filename in MYOBJ)  
  console.log(MYOBJ[filename]);

I get the following:

{ size: 62464,
  path: 'myDir/upload_e79d8d551721e2f399afbc39d5d5eaab.doc',
  name: 'somefile.doc',
  type: 'application/msword',
  mtime: '2016-05-19T14:52:24.129Z' }

My obvious question is:

Why are the other properties of "file1" not displayed? May be they are not the Object's "ownProperty"? Even so, why does "lastModifiedDate" become "mtime?"


Solution

  • Let me guess ... probably implementation for cosnole.log uses Object.getOwnPropertyDescriptor() and can list all non-enumerable values

    var o = {}
    Object.defineProperty(o, 'nonEnumerableValue', {value: 1})
    
    
    console.log(o) // {}
    console.log(o.nonEnumerableValue) // 1