# How to use or execute a package installed using npm

> Learn how to use an npm package you installed, importing a library like lodash with require(), and running an executable like cowsay with npx.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2018-08-04 | Topics: [Node.js](https://flaviocopes.com/tags/node/) | Canonical: https://flaviocopes.com/how-to-use-npm-package/

When you install using `npm` a package into your `node_modules` folder, or also globally, how do you use it in your Node code?

Say you install `lodash`, the popular [JavaScript](https://flaviocopes.com/javascript/) utility library, using

```bash
npm install lodash
```

This is going to install the package in the local `node_modules` folder.

To use it in your code, you just need to import it into your program using `require`:

```js
const _ = require('lodash')
```

What if your package is an executable?

In this case, it will put the executable file under the `node_modules/.bin/` folder.

One easy way to demonstrate this is [cowsay](https://www.npmjs.com/package/cowsay).

The cowsay package provides a command line program that can be executed to make a cow say something (and other animals as well 🦊).

When you install the package using `npm install cowsay`, it will install itself and a few dependencies in the node_modules folder:

![The node_modules folder content](https://flaviocopes.com/images/how-to-use-npm-package/node_modules-content.png)

There is a hidden .bin folder, which contains symbolic links to the cowsay binaries:

![The binary files](https://flaviocopes.com/images/how-to-use-npm-package/binary-files.png)

How do you execute those?

You can of course type `./node_modules/.bin/cowsay` to run it, and it works, but [npx](https://flaviocopes.com/npx/), included in the recent versions of [npm](https://flaviocopes.com/npm/) (since 5.2), is a much better option. You just run:

```bash
npx cowsay
```

and npx will find the package location.

![Cow says something](https://flaviocopes.com/images/how-to-use-npm-package/cow-say.png)
