8

In es6 I can do this:

const { findIndex, last } from 'lodash';

Can I do the same in commonjs with require?

dagda1
  • 26,856
  • 59
  • 237
  • 450

2 Answers2

19

Yes, you can use destructuring in the same way in node v6 and superior. More info here: Destructuring in Node.JS

Example:

const { findIndex, last } = require('lodash');
jc-alvaradov
  • 342
  • 3
  • 12
2

You can pick parts of lodash to require, there are example on the lodash docs page

e.g.

const at = require('lodash/at');
bsyk
  • 1,938
  • 18
  • 20