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

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.

Related

How to run an existed language server without vscode

I am trying to develop my own IDE with language server protocol support, so i download language server written in typescript and try to start them with Node.js.
First, I packaged the server package with webpack. and then start with the command "node server.js", server.js is produced by webpack. but I got
Error: Connection input stream is not set. Use arguments of createConnection or set command line parameters: '--node-ipc', '--stdio' or '--socket={number}'
at D:\GitHub\vscode-autohotkey2-lsp\server\dist\server.js:1:172642
at t.createConnection (D:\GitHub\vscode-autohotkey2-lsp\server\dist\server.js:1:179222)
at Object.999 (D:\GitHub\vscode-autohotkey2-lsp\server\dist\server.js:1:72865)
at n (D:\GitHub\vscode-autohotkey2-lsp\server\dist\server.js:1:186299)
at D:\GitHub\vscode-autohotkey2-lsp\server\dist\server.js:1:186653
at Object.<anonymous> (D:\GitHub\vscode-autohotkey2-lsp\server\dist\server.js:1:186661)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
then I followed the Error information, replaced the command with "node server.js --node-ipc". the error above didn't appear again, but i didn't got a server process in my Windows task manager.
I am new to typescript and language-server-protocol, did I got sth wrong or misunderstand sth?

Creating a migration in knex.js is throwing an error

I am trying to create a migration and it throws the following error
yarn run v1.6.0
(node:14212) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usabil
ity issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods in
stead.
$ babel-node node_modules/.bin/knex migrate:make create_linky_table
C:\Users\Sagar\Desktop\linky\api\node_modules\.bin\knex:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.newLoader [as .js] (C:\Users\Sagar\Desktop\linky\lms-linky\api\node_modules\pi
rates\lib\index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I have the following set up in my script in package.json
"knex": "babel-node --require ./node_modules/dotenv/config node_modules/.bin/knex --knexfile='src/knexfile.js'",
I am using the following code to create the migration
yarn knex make:migration create_linky_table
I am currently using windows and i came upon this answer . Could it be a windows issue?
What #Mikael Lepistö said is correct.
I faced similar issue while doing migration scripts on windows.
My previous command was:
babel-node node_modules/.bin/knex --knexfile src/database/knexfile.js migrate:latest
I changed it to:
babel-node node_modules/knex/bin/cli.js --knexfile src/database/knexfile.js migrate:latest
And the error has gone. May be changing the reference from .bin/knex to /knex/bin/cli.js will make the magic for youso give it a try
Sounds like C:\Users\Sagar\Desktop\linky\api\node_modules\.bin\knex script in windows is not JavaScript executable, but actually shell script wrapper in Windows. So when you try to use babel-node or node to execute it, node interpreter fails because you are trying to run bash/sh shell script with it.
Check out what is stored inside the C:\Users\Sagar\Desktop\linky\api\node_modules\.bin\knex script and if there is a way to override, which node interpreter is used, you can override it with babel-node. If there is no way to override it, you can just check out if it calls for example node_modules/knex/bin/cli.js and call directly that with babel-node.
I would check those out myself, but I don't have Windows node tools setup on this desktop.

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.

Nodeunit debugging in windows

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

Resources