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 ? 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 How to read and write files in Node JS ? NodeJS provides built-in modules for reading and writing files, allowing developers to interact with the file system asynchronously. These modules, namely fs (File System), offer various methods for performing file operations such as reading from files, writing to files, and manipulating file metada 2 min read How to Setup View Engine in Node.js ? View engines are useful for rendering web pages. There are many view engines available in the market like Mustache, Handlebars, EJS, etc but the most popular among them is EJS which simply stands for Embedded JavaScript. It is a simple templating language/engine that lets its user generate HTML with 2 min read How to Convert PNG to JPG using Node.js ? The following approach covers how to convert PNG to JPG in Node.js using Jimp module. Jimp is an image processing library that we can use to do a lot of operations on images. Jimp stands for JavaScript Image Manipulation Program. ApproachTo convert PNG to JPG using Node.js. We will Import Jimp modul 2 min read How to Access the File System in Node.js ? In this article, we looked at how to access the file system in NodeJS and how to perform some useful operations on files. Prerequisite: Basic knowledge of ES6Basic knowledge of NodeJS NodeJS is one of the most popular server-side programming frameworks running on the JavaScript V8 engine, which uses 3 min read How To Read a File Line By Line Using Node.js? To read a file line by line in Node.js, there are several approaches that efficiently handle large files and minimize memory usage. In this article, we'll explore two popular approaches: using the Readline module (which is built into Node.js) and using the Line-reader module, a third-party package. 3 min read Like