Cannot debug NodeJS application - node.js

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.

Related

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 .

how can i fix this error that nodemon keep on showing

i following an express.js tutorial andd after some code and functionalities with api requests i followed exactly how he changed the code that handles these requests into a seperate js file in another folder just to clean up the code but after i did that this error showed up
i tried changing the file name , i tried removing the node-modules folder and running npm install again and i tried installing the module with the issue
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '/routes/api/members'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (C:\Users\Get_Rico\Desktop\crashcoursse\index.js:11:25)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
[nodemon] app crashed - waiting for file changes before starting...
i expect nodemon to save the changes and work just fine with no errors just like what happened in the tutorial
It appears the error is probably coming from this line of code and it's telling you that it can't find the '/routes/api/members' module file.
And, this would not be working because you're trying to load a local module without a proper path name. If no path is specified, then it tries to load a global or built-in module. If that module is in the current directory, then you should use the correct path:
const yourModule = './routes/api/members';

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.

Why isn't bin/www command not working in my cloud9 (c9) new run configuration?

I'm following along with a Lynda course on MEAN Stack development and while they are running bin/www command in a "New Run Configuration" and its yielding "debugger listening on port 15454"
whereas for me, when I enter bin/www, I get the following error:
debugger listening on port 15454
module.js:340
throw err;
^
Error: Cannot find module '/home/ubuntu/workspace/bin/www'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.runMain [as _onTimeout] (module.js:497:10)
at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
When you clone a empty repo from BitBucket it creates a workspace folder. Move the contents of that folder to the root of your cloud9 project.
OR
start from scratch and make sure to run "express . --hbs" in the correct folder
Run
**#**:~/workspace (master) $ express . --hbs
Not
**#**:~/workspace/workspace (master) $ express . --hbs

How do I enable --debug for node.js when running GeddyJS

GeddyJS is started by running geddy from the root of the project.
I'm having some trouble getting GeddyJS to run under node.js with debug enabled.
getty installs /usr/local/bin/geddy:
#!/usr/bin/env node
...
which I made a quick copy of, and amended the shebang line:
#!/usr/bin/env node --debug
...
but that does not work, because env can't find 'node --debug'.
I then tried to write a wrapper script to act as the interpreter in the shebang line here:
#!/bin/sh
exec /usr/bin/env node --debug $#
And this time, node is started with a debugger enabled, but the paths must be messed up, or environment must be different, because I am getting missing module exceptions:
$ geddy-debug
debugger listening on port 5858
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module '../lib/geddy'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object. (/usr/local/bin/geddy-debug:4:1)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
This of course works fine if I don't try to enable debugging.
I want to debug in eclipse as per : https://github.com/joyent/node/wiki/Using-Eclipse-as-Node-Applications-Debugger, which works great with just node --debug scriptname.js
Any suggestions are appreciated.
Answering my own question, so others can benefit if they happen to see this:
From the project directory, override the shebang line and invoke the interpreter directly to run the geddy script:
/usr/bin/env node --debug /usr/local/bin/geddy
There's a Debugging Geddy WikiPage with a bit more info.

Resources