- Socket.IO Cookbook
- Tyson Cadenhead
- 353字
- 2021-07-09 21:49:10
Debugging on the server
The same debugging package that is available on the client side is available on the server as well.
The debugging option can be turned on with a Node environmental variable.
Getting ready
To get started with debugging on the server side, you will need to have Node and Socket.IO installed and an existing app that uses Socket.IO. To test this out, you can easily use any of the apps we built in the previous recipes in this chapter.
How to do it…
To get server-side debugging turned on, follow these steps:
- To enable debugging at the time when you start your server, simply include the
DEBUG
environmental variable as the first argument when you start your Node server, as shown in the following code:DEBUG=* node server
- If you would like to persist the
DEBUG
environmental variable without the need to pass it every time you start your Node server, you can export it ahead of time using the following code:export DEBUG=*
- Now, when you start your server, verbose logging will be used with the following code:
node server
- You can always update the
DEBUG
variable or even remove it completely by setting it to null, which will suppress logging entirely, as shown in the following code:export DEBUG=null
How it works…
Node.js environmental variables are available in process.env
in any running Node process. They are often used to set up server-specific configurations, such as database connections and third-party credentials.
The great thing about using environmental variables to define the logging verbosity is that most cloud-based hosting providers allow you to change environmental variables on the fly, so you can easily toggle logging on or off without having to redeploy your code.
There's more…
Similar to client-side logging, you can set the logging type to something other than the wildcard. This allows you to only get debugging messages on the topic you want to listen to.
For example, listening for XHR requests is as simple as passing it to the environmental variables when you start your Node server with the following code:
DEBUG=socket.io:server node server
- ASP.NET Core:Cloud-ready,Enterprise Web Application Development
- Oracle WebLogic Server 12c:First Look
- 流量的秘密:Google Analytics網站分析與優化技巧(第2版)
- MySQL 8 DBA基礎教程
- 實戰Java程序設計
- SAP BusinessObjects Dashboards 4.1 Cookbook
- Scala程序員面試算法寶典
- Haskell Data Analysis Cookbook
- Protocol-Oriented Programming with Swift
- OpenCV 4計算機視覺項目實戰(原書第2版)
- 微服務架構深度解析:原理、實踐與進階
- Access 2010中文版項目教程
- Oracle GoldenGate 12c Implementer's Guide
- 零基礎學C語言第2版
- Couchbase Essentials