gpahal commented :
You need to setup TLS as shown here: https://docs.dgraph.io/deploy#tls-configuration
On the client side, you need to add credentials to the DgraphClientStub constructor sa shown below:
const dgraph = require("dgraph-js");
const grpc = require("grpc");
const clientStub = new dgraph.DgraphClientStub(
// addr: optional, default: "localhost:9080"
"localhost:9080",
// credentials: pass your root certificates here
grpc.credentials.createSsl(root_certs),
);
const dgraphClient = new dgraph.DgraphClient(clientStub);