We would like to use additional JS capabilities as part of our postman collections.
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).
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.
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.
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:
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);
}
})();