node.js cannot find module "mongodb" - node.js

I'm trying to connect my node js file to mongodb but I keep running into this error. mongodb is in the node_modules file. I'm unsure of what Im doing wrong
node mongstuff.js
internal/modules/cjs/loader.js:670
throw err;
^
Error: Cannot find module '/home/mohammed/node_modules/mongstuff.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)
at Function.Module._load (internal/modules/cjs/loader.js:591:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
at internal/main/run_main_module.js:21:11

Related

Cannot find Module when running Node.js

This is my first time running node.js, and I have file located in C:\source, called index.js. I am not sure what am doing wrong here. I checked if node was installed with node -v and the version number appeared so that seems fine. Any input?
C:\source>node index.js
internal/modules/cjs/loader.js:783
throw err;
^
Error: Cannot find module 'C:\source\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:780:15)
at Function.Module._load (internal/modules/cjs/loader.js:685:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
index.js has:
console.log('Hello World')

Can't run node.js server locally

I'd like to run node.js server on my machine but I get this error. What should I do? (Please note I'm not programmer :)
MBP-Mike:~ michal$ node server
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '/Users/michal/server'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
to run a nodejs server:
node
example: if your server file is called server.js
node /Users/Michal/server.js
it seems like you missed the .js extension on your command.
node server.js
Or you can just run
node .

Cannot debug NodeJS application

I'm trying to debug my NodeJS application (v10.4.0), using the command:
node --inspect-brk index.js
What I get trying to connect to chrome://inspect page for my application is:
Error: Cannot find module 'C:\Users\path\to\my\app\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
at startup (internal/bootstrap/node.js:238:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
What am I doing wrong? Thanks
Check which is your entry point, as you mentioned you are trying to debug with index.js but if does not exist then it shows the cannot find module error.

Cannot find module '..\npm\node_modules\yo\lib\cli.js'

when i am trying to add endpoints using command "yo angular-fullstack:endpoint name", i am getting this error:
module.js:341
throw err;
^
Error: Cannot find module 'C:...npm\node_modules\yo\lib\cli.js'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:140:18)
at node.js:1001:3
while running command npm-install, i am getting this error
> error C2373: '__pfnDliNotifyHook2'
solved by changing the node version to a newer version

Error pointing to non-existent file when running Node.js app locally

I was just sent the files for a Node.js app (which is working without issues online) and I'm trying to set it up on my Windows machine.
I have Node server running, but I'm stuck trying to actually load the app. I can navigate to the directory with the Node command prompt, and there's an app.js (plus folders like config, components etc) in there which I've been trying to run, but I am getting the following error:
D:\my-directory\game-master>node app.js
module.js:327
throw err;
^
Error: Cannot find module 'config'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (D:\posao\aktivni projekti\smart rebellion\game-master
\app.js:7:10)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
The thing is, there is no file titled module.js in the directory. I presume it's a built in Node.js file, but then how do I troubleshoot this?
My best reading of the error is that there should be a config.js file somewhere, but that doesn't make sense because these same exact files work with no hickups on a remote server.
If you want to require('./config'), where config is a directory, the file ./config/index.js should exist.
You can't require('config') however, because node.js will try to find it in node_modules.
Check out node.js modules documentation where the require algorithm is well explained.

Resources