Importing npm module into Postman

We would like to use additional JS capabilities as part of our postman collections.

  1. How do we import npm modules and 3rd party functions into postman? For example: is-port-reachable module through which we would be able to check all open ports on a remote host, given the IP address (similar to nmap).
  2. If importing 3rd party libraries is not possible, is there a similar functionality in postman? We want to scan all open ports on a remote host.

You can’t import NPM modules into Postman.

Have a look at the following links to see which external libraries are available within the Sandbox.

Postman JavaScript reference | Postman Learning Center

JavaScript libraries — Postman Quick Reference Guide Version 1.9.1 - January 2023 documentation (postman-quick-reference-guide.readthedocs.io)

Adding External Libraries in Postman | Postman Blog

I don’t know about #2. Postman wasn’t built built for security testing. Your better off looking at proper vulnerability scanning software that will tell you about your ports but do a lot more than that. Tenable is the main one that comes to mind, but its expensive. There are cheaper alternatives.

Or just write this in node yourself. You can import whatever libraries you want including chai for assertions, and Mocha for the test library. You can do whatever you want then. If you are already comfortable with node, this is probably the most flexible option.

3 Likes

There’s also this collection that shows different ways of importing external libraries:
https://www.postman.com/postman/workspace/postman-answers/documentation/13455110-7a6c90f0-0062-4089-b206-27c803dc1c37?entity=&branch=&version=

Thanks for the response

Thank you, will look into it.

Since this is one of the top results for “NPM + Postman” when googling, let me be a helpful guide for others.

Yes, you now can! As of April 2025, Postman now supports importing npm modules in the scripting environment. This means that you, the developer, can import packages like:

const { v3 } = pm.require('npm:uuid');

Read up on the learning center documentation (Import packages from external registries in Postman | Postman Docs) to learn more about the external package support, which is not limited to NPM but also JSR (JS Registry).

Finally, while the package is-port-reachable can be imported, you’ll note it doesn’t quite work exactly like you’d expect and that’s because packages with network access are restricted for security purposes. So to solve your precise use case, I recommend just using pm.sendRequest directly, something like this:

(async () => {
  try {
    const response = await pm.sendRequest('http://google.com:80', { timeout: 1000 });
    console.log('Port is open', response.statusCode);
  } catch (err) {
    console.log('Port is closed or host is unreachable', err.message);
  }
})();
2 Likes