Importing npm module into Postman

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);
  }
})();
3 Likes