- 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
- Reporting with Visual Studio and Crystal Reports
- SoapUI Cookbook
- Java高并發核心編程(卷2):多線程、鎖、JMM、JUC、高并發設計模式
- C和C++安全編碼(原書第2版)
- OpenCV 3和Qt5計算機視覺應用開發
- 用戶體驗增長:數字化·智能化·綠色化
- Visual C#.NET程序設計
- Scala編程實戰(原書第2版)
- 焊接機器人系統操作、編程與維護
- C語言程序設計上機指導與習題解答(第2版)
- Microsoft Dynamics AX 2012 R3 Financial Management
- ASP.NET程序開發范例寶典
- 絕密原型檔案:看看專業產品經理的原型是什么樣
- IBM DB2 9.7 Advanced Application Developer Cookbook
- Learning Java Lambdas