Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node:util module not found #306

Open
vijeetvinod1204 opened this issue Nov 6, 2023 · 6 comments
Open

node:util module not found #306

vijeetvinod1204 opened this issue Nov 6, 2023 · 6 comments

Comments

@vijeetvinod1204
Copy link

I have no idea how to resolve this:
image

@jsumners
Copy link
Member

jsumners commented Nov 6, 2023

What is that from?

@vijeetvinod1204
Copy link
Author

vijeetvinod1204 commented Nov 6, 2023

This is my middleware:

const pino = require("pino");
const globalLogger = require("../helpers/globalLogger");
global.req = undefined;
const genRequestId = (req, res) => {
  let id = req.get("X-Request-Id");
  if (!id) {
    id = (Date.now() + Math.random()).toString(36).replace(".", "-");
  }
  req.id = id;
  return id;
};
const httpLoggerMiddleware = pinoHttp({
  genReqId: () => undefined,
  logger: globalLogger,
  serializers: {
    req(req) {
      req.body = req.raw.body;
      return req;
    },
  },
  wrapSerializers: true,
  customLogLevel: function (req, res, err) {
    if (res.statusCode >= 400 && res.statusCode < 500) {
      return "warn";
    } else if (res.statusCode >= 500 || err) {
      return "error";
    } else if (res.statusCode >= 300 && res.statusCode < 400) {
      return "silent";
    }
    return "info";
  },
  customSuccessMessage: function (req, res) {
    if (res.statusCode === 404) {
      return "resource not found";
    }
    return `${req.method} completed`;
  },
  customReceivedMessage: function (req, res) {
    return "request received: " + req.method;
  },
  customErrorMessage: function (req, res, err) {
    return "request errored with status code: " + res.statusCode;
  },
  customProps: function (req, res) {
    return {
      userid: req.headers.userid,
      reqId: genRequestId(req, res),
    };
  },
});
module.exports = httpLoggerMiddleware;

@vijeetvinod1204
Copy link
Author

My application won't deploy because of the above error. Not sure where it is coming from.

@vijeetvinod1204
Copy link
Author

const requestLoggerWrapper = (level, req, ...data) => {
  if (!req) {
    return globalLogger[level]({
      message: data.shift(),
      extraParams: JSON.stringify(data),
    });
  }
  if (data[0].length === 1) {
    return globalLogger[level]({
      reqId: req.id,
      userid: req.headers.userid,
      message: data[0],
    });
  }
  return globalLogger[level]({
    reqId: req.id,
    userid: req.headers.userid,
    message: data.shift(),
    extraParams: JSON.stringify(data),
  });
};
const requestLogger = {
  trace: (req, ...data) => requestLoggerWrapper("trace", req, ...data),
  debug: (req, ...data) => requestLoggerWrapper("debug", req, ...data),
  info: (req, ...data) => requestLoggerWrapper("info", req, ...data),
  warn: (req, ...data) => requestLoggerWrapper("warn", req, ...data),
  error: (req, ...data) => requestLoggerWrapper("error", req, ...data),
  fatal: (req, ...data) => requestLoggerWrapper("fatal", req, ...data),
  log: requestLoggerWrapper,
};
module.exports = requestLogger;

@vijeetvinod1204
Copy link
Author

I think any changes pushed post Oct 26 have caused this.

@jsumners
Copy link
Member

jsumners commented Nov 6, 2023

Please provide a minimal reproducible example. Doing so will help us diagnose your issue. It should be the bare minimum code needed to trigger the issue, and easily runnable without any changes or extra code.

You may use a GitHub repository to host the code if it is too much to fit in a code block (or two).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants