I am new to node.js. I am debugging one of the server startup script written using typescript backed by various node.js npm modules. IDE I am using VSCode. Is there any way to get all the function execution log. Server startup functions are mostly async functions with a callback. That's why I would like to get all the functions in the order they were executed and which thread is executing the functions.
Could you please let me know is there any way to achieve this instead of writing console.log in every function or putting breakpoints in every functions?
Follwoing is the code used to import and use the tracing library. I have all 3 first line to resolve the issue.
const { njsTrace} = require("NJSTrace");
import * as njsTrace from 'NJSTrace';
var njsTrace = require('njsTrace.js');
njsTrace.inject();
I have added following to package.json
"dependencies": {
"@apollo/gateway": "latest",
"apollo-server": "^2.5.1-alpha.1",
"graphql": "latest",
"njstrace": "^1.1.2"
},
"typeRoots": [
"./node_modules/@types",
"./types"
]
I have added below index.d.ts in node_modules/@types/njsTrace
export = NJSTrace;
export as namespace NJSTrace;
declare namespace NJSTrace {}
declare class NJSTrace{
inject(config: any): NJSTrace;
}
Now I am getting below error
/usr/local/bin/node --inspect-brk=31111 gateway.js
Debugger listening on ws://127.0.0.1:31111/83e82a13-81df-42bb-9a86-87407cd4b15b
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
(node:5094) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'inject' of undefined
at /Users/Debopam/Documents/To Delete/federation-demo-master/gateway.js:19:12
at Object.<anonymous> (/Users/Debopam/Documents/To Delete/federation-demo-master/gateway.js:28:3)
at Module._compile (internal/modules/cjs/loader.js:773:14)
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)
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)
warning.js:18
(node:5094) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
warning.js:18
(node:5094) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.