An open API service indexing awesome lists of open source software.

https://github.com/matt-ball/postman-external-require

Import node packages inside Postman.
https://github.com/matt-ball/postman-external-require

Last synced: 29 days ago
JSON representation

Import node packages inside Postman.

Awesome Lists containing this project

README

        

# Postman External Require

Use Node packages not bundled into Postman's sandbox.

## 1. Setup on local machine

Clone this repo.

`npm i`

`node index.js`

## 2. Setup in Postman

If you want to jump right into it, import this prebuilt collection and create a global variable called `require` with value `uniq,slapdash,pad-left`:

[![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/d76d17db442b465cfe3f)

Read on for getting this working with your own existing collection..

Add the following script to the `Pre-Request Script` of your collection:

```js
const reqs = pm.globals.get('require');
const pkgs = pm.globals.get('packages');
const installed = pm.globals.get('installedPackages');

if (pkgs && (reqs === installed)) {
eval(pkgs)
} else {
pm.sendRequest({
url: `localhost:3000?packages=${reqs}`,
method: 'GET'
}, (err, res) => {
if (!err) {
eval(res.text());
pm.globals.set('installedPackages', reqs);
pm.globals.set('packages', res.text());
}
});
}
```

Create a global variable in Postman called `require`. Provide a comma separated listed of packages you need e.g. `uniq,slapdash,pad-left`.

`require` your packages in the usual way from within folder/request scripts!