How to resolve the "ReferenceError: util is not defined" error in Node JS

Photo by Joan Gamell on Unsplash

How to resolve the "ReferenceError: util is not defined" error in Node JS

I recently ran into this error: "ReferenceError: util is not defined", while working on a Node JS application and I thought I'd document how I resolved it for later.

Usually, you'll get this error if you're using the Util Node module without first requiring it in your file. To resolve this, you'll want to add this to the top of your file (just around where you've required other modules):

const util = require('util')

Once you've got this, you can use Nodemon to run your server again and it should be working as expected.

Thank you for reading! :)