{"id":14757,"date":"2023-03-20T09:39:38","date_gmt":"2023-03-20T09:39:38","guid":{"rendered":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?p=14757"},"modified":"2023-03-20T09:43:08","modified_gmt":"2023-03-20T09:43:08","slug":"how-to-debug-nodejs-applications","status":"publish","type":"post","link":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/","title":{"rendered":"How To Debug Node.js Applications?"},"content":{"rendered":"\n<p>Node.js is a highly robust, asynchronous and event-driven server-side Javascript technology. And, with Chrome Dev Tools, you can find errors in your code.<\/p>\n\n\n\n<p>In this article, we will get to know the steps to debug your Node.js applications with the help of the debug module, the built-in Node debugger and Chrome&#8217;s developer tools.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Debugging the Node.js Application:<\/h2>\n\n\n\n<p>One of the best ways to detect issues in Node.js applications is the excessive usage of the console.log for debugging.<\/p>\n\n\n\n<p>Check them below:<\/p>\n\n\n\n<p><strong><em>The debug module<\/em><\/strong><\/p>\n\n\n\n<p>The most popular modules that are required in your project come with a debug module. Using this module, you can enable the third part module, to log into the standard output, stdout.<\/p>\n\n\n\n<p>To check whether a module is using it, double-check the package.json file&#8217;s dependency section.<\/p>\n\n\n\n<p>For using the debug module, you need to set the DEBUG environment variable when you are starting your applications. You can even use the character to wildcard names.<\/p>\n\n\n\n<p>The below line will print all the express-related logs to the standard output.<\/p>\n\n\n\n<p><strong><em>DEBUG=express* node app.js<\/em><\/strong><\/p>\n\n\n\n<p>You will see the output below:<\/p>\n\n\n\n<p><strong>Built-in Node.js Debugger<\/strong><\/p>\n\n\n\n<p>Node.js includes a fully-featured debugging utility that can be easily accessed through a TCP-based protocol and a built-in debugging client.<\/p>\n\n\n\n<p>To start the built-in debugger, you need to start the application by entering the command given below:<\/p>\n\n\n\n<p><strong><em>node debug app.js<\/em><\/strong><\/p>\n\n\n\n<p>After you have entered this, you will get to see the output, as given below:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Descriptions of the Node.js Debugger:<\/h2>\n\n\n\n<p>c =continue to execute the code<\/p>\n\n\n\n<p>n=execute this line and go to the next line<\/p>\n\n\n\n<p>s= step into this function<\/p>\n\n\n\n<p>o=finish function execution and step out<\/p>\n\n\n\n<p>repl=allows code to be evaluated remotely<\/p>\n\n\n\n<h4 style=\"background-color: #D5EAFF; padding: 10px;\">Pick A MilesWeb&#8217;s <a href=\"https:\/\/www.milesweb.co.uk\/hosting\/nodejs-hosting\" target=\"_blank\" rel=\"noopener\">NodeJs Hosting Server<\/a> Ultimate Power, Speed And Top-Class Security!<\/h4>\n\n\n\n<p>You can even add breakpoints to the application by inserting the debugger statement into your codebase.<\/p>\n\n\n\n<p><strong><em>function add (a, b) {<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp; debugger<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp; return a + b<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>}<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>var res = add(&#8216;abc&#8217;, 3)<\/em><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Watchers<\/h3>\n\n\n\n<p>You can watch the expressions and variables during the process of debugging. On each of the breakpoints, every expression from the watcher&#8217;s list will be evaluated in the present context and displayed immediately before the breakpoints source code listing.<\/p>\n\n\n\n<p>To use the watchers, you need to define them for expressions you need to watch. To do so, you need to do it in the below way:<\/p>\n\n\n\n<p><strong><em>watch (&#8216;expression&#8217;)<\/em><\/strong><\/p>\n\n\n\n<p>Now, to get a list of active watchers, type watchers, to unwatch an expression:<\/p>\n\n\n\n<p><strong><em>unwatch (&#8216;expression&#8217;)<\/em><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Chrome Debugger<\/h3>\n\n\n\n<p>When you debug complex applications, visuals can help. It would be good to use the familiar UI of the Chrome DevTools for debugging the Node.js applications.<\/p>\n\n\n\n<p>The best part is, the Chrome Debug protocol has been ported into the Node.js module and can be ideally used for debugging the Node.js applications.&nbsp; To do so, you need to first install the node-inspector:<\/p>\n\n\n\n<p><strong><em>npm install -g node-inspector<\/em><\/strong><\/p>\n\n\n\n<p>You can start debugging your applications by doing it in a below way:<\/p>\n\n\n\n<p><strong><em>node-debug index.js &#8211;debug-brk<\/em><\/strong><\/p>\n\n\n\n<p>It will extend the Chrome Developer tools, and you can start to debug your Node.js applications with it.<\/p>\n\n\n\n<p><strong>Conclusion<\/strong><\/p>\n\n\n\n<p>In this article, we have seen how to debug a remote application using Chrome DevTools. In the DevTools, you can see the variable changes and track bugs easily without printing to the console with the help of the watch variables and breakpoints.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Node.js is a highly robust, asynchronous and event-driven server-side Javascript technology. And, with Chrome Dev Tools, you can find errors in your code. In this article, we will get to know the steps to debug your Node.js applications with the help of the debug module, the built-in Node debugger and Chrome&#8217;s developer tools. Debugging the [&hellip;]<\/p>\n","protected":false},"author":34,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[2948,2959],"class_list":["post-14757","post","type-post","status-publish","format-standard","placeholder-for-hentry","category-web-hosting-faq","tag-node-js-2","tag-node-js-applications"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Debug Node.js Applications? | MilesWeb<\/title>\n<meta name=\"description\" content=\"You can debug node.js applications with the help of built-in Node debugger and Chrome\u2019s developer tools. In this article, we will understand the steps.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Debug Node.js Applications? | MilesWeb\" \/>\n<meta property=\"og:description\" content=\"You can debug node.js applications with the help of built-in Node debugger and Chrome\u2019s developer tools. In this article, we will understand the steps.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Hosting FAQs by MilesWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-20T09:39:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-20T09:43:08+00:00\" \/>\n<meta name=\"author\" content=\"Nehal Khatri\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nehal Khatri\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/\",\"name\":\"How To Debug Node.js Applications? | MilesWeb\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\"},\"datePublished\":\"2023-03-20T09:39:38+00:00\",\"dateModified\":\"2023-03-20T09:43:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/0241ea191f60975839d956b6952e0a1d\"},\"description\":\"You can debug node.js applications with the help of built-in Node debugger and Chrome\u2019s developer tools. In this article, we will understand the steps.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Debug Node.js Applications?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\",\"name\":\"Web Hosting FAQs by MilesWeb\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/0241ea191f60975839d956b6952e0a1d\",\"name\":\"Nehal Khatri\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/736396ef8d8bdecec53ce8851058903e?s=96&d=blank&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/736396ef8d8bdecec53ce8851058903e?s=96&d=blank&r=g\",\"caption\":\"Nehal Khatri\"},\"description\":\"Nehal is an ardent content writer. She's passionate about crafting content that's simple but adds value. Her insatiable interest in writing has allowed her to explore her skills. She is adept and can write for different types of content formats.\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/nehal-khatri\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Debug Node.js Applications? | MilesWeb","description":"You can debug node.js applications with the help of built-in Node debugger and Chrome\u2019s developer tools. In this article, we will understand the steps.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/","og_locale":"en_GB","og_type":"article","og_title":"How To Debug Node.js Applications? | MilesWeb","og_description":"You can debug node.js applications with the help of built-in Node debugger and Chrome\u2019s developer tools. In this article, we will understand the steps.","og_url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/","og_site_name":"Web Hosting FAQs by MilesWeb","article_published_time":"2023-03-20T09:39:38+00:00","article_modified_time":"2023-03-20T09:43:08+00:00","author":"Nehal Khatri","twitter_misc":{"Written by":"Nehal Khatri","Estimated reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/","name":"How To Debug Node.js Applications? | MilesWeb","isPartOf":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website"},"datePublished":"2023-03-20T09:39:38+00:00","dateModified":"2023-03-20T09:43:08+00:00","author":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/0241ea191f60975839d956b6952e0a1d"},"description":"You can debug node.js applications with the help of built-in Node debugger and Chrome\u2019s developer tools. In this article, we will understand the steps.","breadcrumb":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-debug-nodejs-applications\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/"},{"@type":"ListItem","position":2,"name":"How To Debug Node.js Applications?"}]},{"@type":"WebSite","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/","name":"Web Hosting FAQs by MilesWeb","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/0241ea191f60975839d956b6952e0a1d","name":"Nehal Khatri","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/736396ef8d8bdecec53ce8851058903e?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/736396ef8d8bdecec53ce8851058903e?s=96&d=blank&r=g","caption":"Nehal Khatri"},"description":"Nehal is an ardent content writer. She's passionate about crafting content that's simple but adds value. Her insatiable interest in writing has allowed her to explore her skills. She is adept and can write for different types of content formats.","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/nehal-khatri\/"}]}},"views":98,"_links":{"self":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/14757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/comments?post=14757"}],"version-history":[{"count":3,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/14757\/revisions"}],"predecessor-version":[{"id":14760,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/14757\/revisions\/14760"}],"wp:attachment":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/media?parent=14757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/categories?post=14757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/tags?post=14757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}