Can send Google Analytics events using gtag from my Node.js express server?

right not I’ve a kind of complex server error logging system that I would to refactor in order to Google Analytics.

Is there a way to do something like this on my Node.js express server?

// INSTANTIATE THE gtag SOMEHOW

gtag("event", "server_error", {
  error_msg: "SOME ERROR MSG",
  path: req.path
});

I’m using Google Analytics 4 and I’m sending data using gtag.