Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Socket.IO Cookbook

You're reading from  Socket.IO Cookbook

Product type Book
Published in Oct 2015
Publisher Packt
ISBN-13 9781785880865
Pages 184 pages
Edition 1st Edition
Languages
Author (1):
Tyson Cadenhead Tyson Cadenhead
Profile icon Tyson Cadenhead

Table of Contents (15) Chapters

Socket.IO Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Wiring It Up 2. Creating Real-Time Dashboards 3. Having Two-Way Conversations 4. Building a Room with a View 5. Securing Your Data 6. Performing a Load Balancing Act 7. Streaming Binary Data 8. Integrating with Mobile Applications Index

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:

  1. 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
  2. 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=*
  3. Now, when you start your server, verbose logging will be used with the following code:

    node server
  4. 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
You have been reading a chapter from
Socket.IO Cookbook
Published in: Oct 2015 Publisher: Packt ISBN-13: 9781785880865
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}