Express.js help (internal/modules/cjs/loader.js:985 throw err; ^)

Hi everyone.
i am connected to a mongodb cluster already but when i create new folders(models and controllers) and files(User.js, RegisterController.js) in my express app i get this error:

" internal/modules/cjs/loader.js:985 throw err; ^
Error: Cannot find module ‘./controllers/RegisterController.js’
Require stack:

  • C:\Users\Gaziem\bitcube-project\server\app.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object. (C:\Users\Gaziem\bitcube-project\server\app.js:7:28)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions…js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
    code: ‘MODULE_NOT_FOUND’,
    requireStack: [ ‘C:\Users\Gaziem\bitcube-project\server\app.js’ ]

please help me with this error
node version- 12.16.1

please see images of my code attached

Looks like controllers is in the ‘src’ folder. I think suppose to be: ./src/controllers

thanks i tried that now but still not running

Try restarting the server. Also, did you use VsCode intelligence to write the file names and path?

I would suggest letting vscode do it. See if you can use the terminal to nano into the file from the src directory.


In src dir:

nano ./controllers/RegisterController.js

*Sorry for spelling mistakes.

In the Register Controller, assign the object a name, then do:

module.exports = `name of object`

i tried those methods you listed, its still not running. theres an exact same error problem listed on github as well but it doesnt have the right answer

This type of problem is probably not on github. It is a file path issue.

thanks so much for trying to help i got it to work earlier, the “const registerController” on top had to start with capital letter.