0

I need to solve a simple DNS query using njs in nginx.

I've searched but it seems that there isn't a 'native' function for doing this.

So I'm trying to use dns-lookup module for node.js I've installed it using npm install dns-lookup, then I've tried to use it in my njs script, with something like:

var lookup = require('dns-lookup');
ip = lookup.resolve(hostname);

But when I run this script I receive an error:

[error] 13555#13555: *124 js exception: Error: Cannot find module "dns-lookup"

1st question, is it right what I'm doing? How can I load an external module in my js file?

2nd question, do you know how to solve? And/or is there a better way for do a DNS resolution?

I've found a similar question here in stackoverflow but without answers

Thanks in advance

Fabio
  • 55
  • 1
  • 7
  • Wouldn't it be `require('dns');`? See https://nodejs.org/api/dns.html#dns_dns – digijay Apr 27 '20 at 16:38
  • @digijay I've tried also to use dns (I forgot to mention on my question) but I got the same error. It seem a generic issue on loading an external module in njs. I've tried also to load them using the full path but with the same result. Not sure if it's a limitation of njs, I cannot find documentation about this – Fabio Apr 27 '20 at 16:55

0 Answers0