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.
- Host: GitHub
- URL: https://github.com/matt-ball/postman-external-require
- Owner: matt-ball
- License: mit
- Created: 2019-08-01T23:08:34.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-02-13T06:24:58.000Z (4 months ago)
- Last Synced: 2025-04-08T17:21:22.392Z (about 2 months ago)
- Language: JavaScript
- Size: 63.5 KB
- Stars: 36
- Watchers: 3
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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`:
[](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!