Node.js Project to Convert HTML to Jade Template Using html2jade Library in Javascript Full Tutorial For Beginners

Node.js Project to Convert HTML to Jade Template Using html2jade Library in Javascript Full Tutorial For Beginners

 

Welcome folks today in this post we will be converting  html to jade template using html2jade library in javascript. All the source code of the application will be shown below.

 

 

 

 

Get Started

 

 

 

In order to get started we need to install html2jade command line library globally inside our system. We need to issue the following npm command with the -g global flag

 

npm i -g html2jade

 

After executing this command the library will be globally installed on your system and you will be able to use this library

 

 

 

Usage

 

 

 

Now to use this library command first of all we will be converting html from a url to jade template

 

Let’s suppose we want to convert from twitter.com we will write

 

html2jade https://twitter.com

 

 

 

Now to save this result inside a separate file of index.jade you will modify the command as follows

See also  React File Uploader With Express (Using React Hooks)

 

 

html2jade https://twitter.com > index.jade

 

 

 

Programmatic Use

 

 

 

Now to use this library inside your node.js project. You can install this library locally inside your node.js project like this

 

npm i html2jade

 

After this make a index.js file and copy paste the following code

 

index.js

 

 

To convert raw HTML into Jade:

 

 

var html2jade = require('html2jade');
var html = "<html><body>Hello World</body></html>";
html2jade.convertHtml(html, {}, function (err, jade) {
  // do your thing
});

 

 

To convert DOM document into Jade (client-side):

 

 

// assumes html2jade.js file has been loaded
Html2Jade.convertDocument(document, {}, function (err, jade) {
  // do your thing
});

 

Leave a Reply