How to highlight syntax in files using Node.js ? Last Updated : 07 Apr, 2021 Comments Improve Suggest changes Like Article Like Report Node.js supports modules and packages that can be installed using NPM, which allows us to exploit various functionalities. One such functionality is syntax highlighting using Node.js that helps us to render highlighted code as static HTML, or we can also use it for dynamic syntax highlighting. The following approach covers how to highlight syntax files in Node.js using highlight.js module. Highlight.js works as a syntax highlighter with automatic language detection. It is written in JavaScript and is supported on the browser as well as on the server. Module Installation: Use the following command to install highlight.js module using npm from your terminal. npm install highlight.js After installing from npm, we can use the package in our code as follows: const hljs = require('highlight.js'); CDN Import: We can use the following way to import the module on HTML page. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.1/styles/default.min.css"> Example: We have highlighted GeeksForGeeks text in the following example. We have imported highlight.js into our code using CDN and then we have written the desired code into <pre> tag. HTML <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <!-- Using highlight.js through CDN link --> <link rel="stylesheet" href= "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.1/styles/default.min.css"> <!-- Installing highlight.js through CDN --> <script src= "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.1/highlight.min.js"> </script> </head> <body> <pre> <!-- Here we have used < and > because using angle brackets will be interpreted as actual HTML code --> <code class="html"> <strong>GeeksForGeeks</strong> </code> </pre> <script type="text/javascript"> // Using highlightAll method to // highlight the code hljs.highlightAll(); </script> </body> </html> Output: References: https://highlightjs.org/usage/ Comment More infoAdvertise with us Next Article How to highlight syntax in files using Node.js ? G greenblade29 Follow Improve Article Tags : Web Technologies Node.js Node.js-Methods NodeJS-Questions Similar Reads How to Handle Syntax Errors in Node.js ? If there is a syntax error while working with Node.js it occurs when the code you have written violates the rules of the programming language you are using. In the case of Node.js, a syntax error might occur if you have mistyped a keyword, or if you have forgotten to close a parenthesis or curly bra 4 min read How to add Text Highlighter in Next.js ? In this article, we are going to learn how we can add Text Highlighter in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components con 2 min read How to highlight text based on user input with React.js ? One common feature in many applications is the ability to highlight specific portions of text based on user input. In this article, we will explore how to implement text highlighting functionality using React.js. The following approach covers how to highlight text input given by users in ReactJS. It 2 min read How to Create and Use a Syntax Highlighter using JavaScript? A syntax highlighter is a tool that colorizes the source code of programming languages, making it easier to read by highlighting keywords, operators, comments, and other syntax elements in different colors and fonts. In JavaScript, you can create a syntax highlighter by either manually writing your 3 min read How to Get Information About a File using Node.js ? Node.js is an open-source and cross-platform runtime environment built on Chromeâs V8 JavaScript engine for executing JavaScript code outside of a browser. You need to recollect that NodeJS isnât a framework, and itâs not a programming language. In this article, we will discuss how to get informatio 3 min read Like