JavaScript Utils Module Not Found

Hello, I am currently learning Express.js on the “Create a Back-End App with JavaScript” course. I am having trouble using the utils module in the following segment of code in VSCode on Windows 10.

const { getElementById, getIndexById, updateElement,
seedElements, createElement } = require(’./utils’);

This code segment is from:

When I run my JavaScript program, an error appears that reads: Error: Cannot find module ‘./utils’. This error is also attached in the first image.

I have looked at the Codecademy and various other help forums. I downloaded node.js version 14.17.0 from Node.js.

I have tried the following:

  1. npm install utils --save
  2. npm cache clean -f
  3. Deleting the node_modules folder, package.json, package-lock.json, and then running npm install

When I try npm install utils --save, I get a warning message attached in the second image. Then when I try to run the program with node fileName.js, the same error from before appears: Error: Cannot find module ‘./utils’

The problem appears to be unique to the utils module, since I am able to run the express module with no problems.

How could I fix the utils module error?

Thank you in advance for your help.

In this project, it appears ./utils is refering to a file included in the project. If you downloaded the files to do this project on your own computer, you may have missed the utils.js file, or your file structure may not match (ie. the utils.js file may not be on the same level as the file you are attempting to import the functions to). Here’s a screenshot of the project showing the file structure in the CC environment:

1 Like

Thank you! That seemed to have fixed the issue. I thought that utils was a module that I could install like express, but I didn’t notice it’s actually a file from the project.

1 Like