Debugging and troubleshooting Node.js proxies
It's a good practice to make sure any Node.js code you add to a proxy works before you deploy it to Edge. This topic discusses ways to debug and troubleshoot proxies that include Node.js applications after they are deployed.
If you notice slow performance, you may be able to solve the problem by increasing the default Node.js connection pool size with maxSockets, or by disabling socket pooling altogether. For more information and example code, see Node.js Performance Tips: Socket Pooling in the Apigee Community.
To view log information about your Node.js application:
- In the main API proxies page, click on the proxy you wish to view.
- In the summary page of the selected proxy, click Node.js Logs on the right-hand side of the tool bar.
The Node.js Logs button does not appear for non-Node.js API proxies.
In the Logs page, you can select a time range of logs to view, as shown below. The logs record HTTP method calls, success or failure of calls, console.log messages, and so on. Enter a search string in the search field to display all log entries that contain the string.
The trace tool is useful for general proxy debugging. For detailed information on using the trace tool, see Using the Trace tool.
You can embed console.log statements in your Node.js code and view the output in the trace tool. For example, the following statement prints the username of the user who is logging in to access the proxy:
console.log('Logging in as %s', config.username);
You can view the output of this console.log message in the trace tool. Simply call your API in the trace tool and open the Script Output panel of the final response, as shown below.
If you are using Ngnix as a proxy and see "Bad Gateway" errors, try increasing the Ngnix proxy timeout configuration as explained here:
proxy_connect_timeout 60; proxy_read_timeout 120;
Depending on how long the server takes to respond can determine your ideal timeout configurations. For example, a read timeout of 45-60 seconds might be ideal to provide a reasonable buffer.
You can also configure the Apigee default timeout values in the HttpTargetConnection element in the TargetEndpoint. The default values are:
connect.timeout.millis - 60 seconds io.timeout.millis - 120 seconds
<HTTPTargetConnection> <Properties> <Property name="connect.timeout.millis">5000</Property> <Property name="io.timeout.millis">5000</Property> </Properties> <URL>http://www.google.com</URL> </HTTPTargetConnection>
See also Endpoint properties reference.
To learn more about debugging, see:
- Using the Trace tool
- Using performance metrics
- Audits: API, Product, and organization history
For information about Node.js module support in Apigee Edge, including information about support for HTTP/HTTPS, TLS, and other advanced topics, see Understanding Edge support for Node.js modules.
Help or comments?
- If something's not working: Ask the Apigee Community or see Apigee Support.
- If something's wrong with the docs: Send Docs Feedback
(Incorrect? Unclear? Broken link? Typo?)