> This page location: /docs.md > /docs/tools-and-connectors.md > /docs/mongodb-vscode.md > /docs/mongodb-vscode/playgrounds.md

> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# Use require() in Playgrounds

You can use the [require()](https://nodejs.org/api/modules.html#modules_require_id) function in your playgrounds to reuse code in your playgrounds. The code you include with `require()` can be either:

- A native Node module (such as [fs)](https://nodejs.org/api/fs.html#fs_file_system)

- An external Node module downloaded from [npm](https://www.npmjs.com/)

- A local JavaScript file

## Use Cases

Using `require()` to import code helps keep your playgrounds organized. If you are often performing the same tasks in your playgrounds, you can use `require()` to reuse code and avoid writing full functions in each of your playgrounds.

For example, consider the following scenarios where reusing code can simplify logic and improve productivity:

- You need to ensure that documents are inserted with a consistent structure. You can import a JavaScript file to validate the data format before the playground script performs the insert.

- You store monetary data and want to convert values between different currencies. You can import a JavaScript function to perform conversion calculations.

- You need to import data from files on your local computer. You can use the native Node module `fs` to read data from local files.

## Get Started

To learn how to use `require()` in your playgrounds, see the following tutorials:

- [Use require() to Include Node.js Modules](https://www.mongodb.com/docs/mongodb-vscode/require-playgrounds/require-modules.md#std-label-vsce-require)

- [Use require() to Load Local Files](https://www.mongodb.com/docs/mongodb-vscode/require-playgrounds/require-local.md#std-label-vsce-require-local)
