Nodeunit debugging in windows - node.js

I am trying to debug tests when running nodeunit and was trying something that is explained in this SO Question but when in try it does not work in Windows.
d:\code\path>node --debug-brk `which nodeunit` test\tests.js
Debugger listening on port 5858
module.js:338
throw err;
^
Error: Cannot find module 'd:\code\path\`which'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.runMain [as _onTimeout] (module.js:501:10)
at Timer.listOnTimeout (timers.js:110:15)
I am trying this in Windows and node_path is in System variables.

which is a unix command, and `which nodeunit` in backticks means: 'print here the path of the nodeunit command'
Sadly on windows neither wich nor backticks works, so you have to do it by hand.
A similar command is where, so you can run 'where nodeunit', take note of the output and then rune
node --debug-brk c:\....\nodeunit test\tests.js

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 .

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.

Error: Cannot find module 'C:\server.js' in Node server for Meanjs

I have git cloned meanjs into a folder in D: drive as shown below and ran the command npm start to start the node server.
admin#admin-PC MINGW32 /d/Udemy Angular 1 projects/Project5/jobfinder (master)
$ npm start
> meanjs#0.5.0 start D:\Udemy Angular 1 projects\Project5\jobfinder
> gulp
[23:41:30] Using gulpfile D:\Udemy Angular 1 projects\Project5\jobfinder\gulpfile.js
....and got the below error.
Error: Cannot find module 'C:\server.js'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
[23:58:35] [nodemon] app crashed - waiting for file changes before starting...
After that, just to give it a try I copied the server.js from the current directory to C:\ and issued 'npm start' command at git bash from the same directory and the error changed to below.
Debugger listening on [::]:5858
module.js:457
throw err;
^
Error: Cannot find module './config/lib/app'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\server.js:6:11)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
[23:41:52] [nodemon] app crashed - waiting for file changes before starting...
Can anyone please help me understand why is Node looking for server.js and other resources at C:\ instead of the current directory? Is there anything very simple I am missing out (though I find it quite strange !). Btw sorry for posting the git bash errors as code since I did not have enough reputations to post more than one image link.
Cheers!
Adding my research ....
Invoking 'npm start' command in meanjs directory hits the file gulpfile.js. Looking into the file, I saw that a gulp task (nodemon) was initiated as below and the script property of the return object was set to 'server.js'.
Code from gulpfile.js.
gulp.task('nodemon', function () {
var nodeVersions = process.versions;
var debugArgument = '--debug';
switch (nodeVersions.node.substr(0, 1)) {
case '4':
case '5':
case '6':
debugArgument = '--debug';
break;
case '7':
debugArgument = '--inspect';
break;
}
console.log('nodemon task'); // checking execution of the callback
return plugins.nodemon({
script: 'server.js',
nodeArgs: [debugArgument],
ext: 'js,html',
verbose: true,
watch: _.union(defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
});
});
The above problem was solved by deleting the Autorun string in the registry at the below path.
"HKEY_CURRENT_USER\Software\Microsoft\Command Processor".
The autorun string was set to C: and as a result Nodemon recognised C: as the root instead of the current directory in Gitbash or command prompt.

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