NodeJS: difference between requests (require)

I started learning NodeJS and noticed that there are some ways to require a file, two of them are:

const app = require('lib').app

const {app} = require('lib')

Is there any difference between them in terms of performance or are both equal? A friend told me he saw somewhere (who doesn't remember) that one of them is heavier and can influence performance whenever the file is run.

Author: Getulio, 2017-08-11

1 answers

Both are equal.

Using const {app} = require('lib') is a new tool that was implemented in ES6 version, called Destructuring assignemt and that it was not possible in the old days. That is, before you had to make an assignment for each property.

In your case it makes little difference but if require('lib') export more properties you can do all in one line:

const {app, router, middleware} = require('lib')
 3
Author: Sergio, 2017-08-11 16:15:17