# How to use import in Node.js

> Learn how to use import instead of require in Node.js by adding type module to your package.json, so you can switch to clean ES modules import syntax.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2022-12-22 | Topics: [Node.js](https://flaviocopes.com/tags/node/) | Canonical: https://flaviocopes.com/how-to-use-import-nodejs/

Using [Node.js](https://flaviocopes.com/book/node/) and you want to stop using `require()`?

```jsx
const fs = require('fs')
```

and instead use the ES modules `import` syntax?

```jsx
import fs from 'fs'
```

You have to do this.

Go in the `package.json` file and add `"type": "module",`, like this:

```jsx
{
  "name": "projectname",
  "version": "1.0.0",
  ...the rest of your file
}
```

```jsx
{
  "name": "projectname",
  "type": "module",
  "version": "1.0.0",
  ...the rest of your file
}
```

That’s it!

You can now use import like

```jsx
import fs from 'fs'
```
