npm modules import in JavaScript

You can include not only your own modules, but also modules installed via npm. At the same time, for your modules, you need to specify ./ before, but for npm modules, you don’t need it.

Let's look at an example. We will install the underscore library:

terminalnpm install underscore

And include it:

src/index.jsimport _ from 'underscore';

Let's use some functions of the imorted library:

src/index.jsimport _ from 'underscore';

let arr = [1, 2, 3, 4, 5]
let res = _.first(arr) + _.last(arr);
console.log(res);

You can import not all functions, but only the necessary ones:

src/index.jsimport {first, last} from 'underscore';

let arr = [1, 2, 3, 4, 5]
let res = first(arr) + last(arr);
console.log(res);
Задание 1

Install the lodash library. Include it to your project and use several methods from this library.