When I use a component like
const React = require('react');
const dns = require('dns');
class DnsResolver extends React.Component {
componentDidMount() {
dns.resolve('https://www.google.com', (err, addresses) => {
this.setState({
address: addresses
});
});
}
render() {
return (
<div>
{this.state.address}
</div>
);
}
}
module.exports = DnsResolver;
the result is 0.0.0.0. Somehow, the browser cannot resolve the address. Why might this happen?
dns.resolve()function for? referencemongodbnpm module. It usesdnsnpm module to resolve the mongodb address, but since it runs at the frontend,dns.resolve()translates into this web extension function. NodeJSdnsreturns an array but web extensiondnsmay returnstring. That's where the trouble starts. I maybe should not usemongodbat the frontend.