0

I come across two different ways of importing modules in Node.js. When do we need to use curly braces to import the modules?

var mongoose = require('mongoose');
var {mongoose} = require('./db/mongoose.js');

In ES6, we can import the named exports using curly braces as follows:

import {mongoose} from './db/mongoose.js'

Is the same rule applicable for importing using require as well?

Prem
  • 4,657
  • 12
  • 38
  • 75
  • its an es6 specification and its called [object destruction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) and it works with import not require. – ShegaMike May 25 '18 at 18:16
  • @Miqe Not really, "destruction" since you're not destroying, but object destructuring.. – Marcos Casagrande May 25 '18 at 18:25
  • 1
    @MarcosCasagrande thanks for the heads up its definitely object destructuring – ShegaMike May 25 '18 at 18:30

0 Answers0