Node.JS, CLI with VSCode not finding path to NPM modules, launch.json - node.js

I want to write a command line program to use via node.js and CLI module. VSCode is not finding .require('cli') so no intellisense.
Then when I launch for debug it isn't looking in the right place, it's looking at APP\npm_modules\cli.js when it is APP\npm_modules\cli\cli.js.
I do have cli installed both locally and globally and I have a NODE_PATH environment pointing accordingly.
The same code works correctly when run at the command line, so it's a VSCode issue. Perhaps, there is a different editor that offers debugging that I should consider?

My mistake. Turns out that I had enabled the debugger to break on all exceptions and as .require resolves, it is looking in several places, eventually the module is found, but there are a number of caught exceptions along the way. I was stuck at looking at the first exception.

Related

LESS #plugin Debugging (node)

Does anyone know how to debug a less plugin when using node to compile? So that I would be able to see the value of console.log() within custom less functions.
I am also using gulp-less. I have tried to run the gulp this way:
node --inspect --debug-brk /usr/local/bin/gulp compilecss
This ran the gulp task but I don't see any console from within the function inside the javascript #plugin.
The above mentioned method worked, the issue was that the plugin wasn't set up correctly. For those who were in my shoes this is what worked:
Follow the instructions on this answer for getting the inspector in the gulp task.
enter link description here
Then if your plugin is installed you should see logs in the console from the less custom plugin or it's functions.

Please specify node.js interpreter correctly WebStorm error

I'm trying to simply create a React Native project via Webstorm but I get this error upon trying to do so which's resulting in myself not being able to start a project.
Whenever I do choose a Node interpreter it gives me an error that says Unspecified react-native cli package at the same spot that says Please specify node.js interpreter correctly.
I've been starting React Native projects like this since the beginning but this time I get this error out of no where, I don't know where it came from. How can I fix this?
Opens up your terminal, and use the which command to find our your NodeJS interpreter
$ which node
/Users/felixfong/.nvm/versions/node/v8.0.0/bin/node
And copy that result, and update your Node interpreter field inside yoru WebStorm
Hopes this help

how can I debug a node app that is started via the command line (cli) like forever or supervisor?

I'm familiar with debugging my own node apps (usually with node-inspector). Today I'd like to debug someone else's program. I'm trying to track down an issue with supervisor. So naturally I just add a --debug (or debug-brk) to the command call, but it passes that to the code that it is supervising.
I've tried adding debugger lines to the js file for supervisor but that didn't work (probably because no debugger was attached at that time). There's a bit of a race here -- I need to start the debugger and attach it to the supervisor process after it starts but before it processes its arguments from the command line.
What I really want to do here is stop supervisor and debug it before it processes its command line arguments. How can I do this?
I had the same problem while developing my hexo blog. The documentation isn't all that complete yet so I find myself needing to reverse engineer at times.
The basic idea is that in Node.js even your cli apps are simply normal node apps that you are exposing to the OS command line interface. On Unix systems you are using this line:
#!/usr/bin/env node
To allow the environment to execute the script.
Many cli based node apps try to insist that you install them globally with the -g option.
npm install -g node-inspector
I personally prefer to have as much control of my development environment as I can get, so I prefer to break some conventions and check my node_modules in to source control along with installing everything I can locally by dropping the -g.
npm install node-inspector
Now you don't have to do this in order to make this work, I'm just describing this setup because it relates to your question. When I run node-inspector I can't simply use:
node-inspector
Instead I must explicitly invoke it from within my project. I do this by executing the symlink in my node_modules/.bin folder:
node_modules/.bin/node-inspector
Now I'm running node-inspector just like you.
Next all I need to do is start the cli process in debug and optionally pass params to it:
node --debug-brk node_modules/.bin/hexo generate
Note I am explicitly calling the symlink here and not simply:
node --debug-brk hexo generate
If I tried the line above I would get an error: "Error: Cannot find module".
I hope this helps.

Yeoman hangs on line 72 of events.js, won't let me do anything

First of all, I'm running this on Windows 8.
So When I install yeoman with npm install -g yo, it seems to work fine.
Then, when I type in the command yo, I get the usual response of:
[?] What would you like to do? (Use arrow keys)
Run the Famous generator (0.2.10)
Update your generators
Install a generator
Find some help
Get me out of here!
But then when I click on, for example,
Update your Generators
I get the following:
Its the exact same error every time, and it's preventing me from using any yeoman generators, which is making it impossible then to use the new Famo.us engine.
So far, I've tried uninstalling and reinstalling Node, Yeoman, and everything in between. I've also tried it in various command prompts, including the standard Windows Command Prompt, Git Bash, NodeJS commandPrompt, and cygwin.
Does anyone know how I can fix this?
One avenue of action I've been thinking about is trying to find this events.js (or whatever other file this error is originating from) and trying to build from there.
Also, this person # Yeoman gifsicle error (and others) seems to be having similar issues, but the fixes mentioned in that question don't seem to be working for me.
Thanks!

node inspector with mocha not working with 'debugger' command

I am using mocha to test my code. I am using node inspector to debug my code.
bash
mocha test/test.* --debug-brk
This works but not so well. It stops at the first line of code in mocha. I want it to stop it at my code. I tried using the 'debugger' key word to make a manual breakpoint but some how it does not stop there.
Try placing a breakpoint at the bottom of the mocha library per this issue. For some reason that allows debugger statements in your modules to pause the node debugger.
However it doesn't seem to stop at debugger statements in the spec itself. I have a SO question highlighting that problem.
I was on the latest node version, using the node-debug command (to launch node-inspector and having the same issues you were. Here's what I'm rolling with currently:
Using the following versions:
node: 0.11.13 (I downgraded from latest) <-- I specifically had to use this one
mocha: 2.2.1 <-- might work with any
node-inspector: 0.9.2 <-- might work with any
Start your tests using the following command:
node-debug _mocha test/unit-tests.js
Navigate to your test file and start putting in breakpoints, then hit run. I usually put one up by the 'requires' of my test file, and several within my 'it' functions.
Hope that helps, and that one day this kind of thing will just work :P
Got the idea to downgrade node from here:
https://www.bountysource.com/issues/7978672-script-is-resumed-as-soon-as-node-inspector-is-loaded
And the command from here:
https://github.com/node-inspector/node-inspector#how-do-i-debug-mocha-unit-tests

Resources