title: How to read and parse html in Nodejs?
body: <p>I have a simple project. I need the help this is a related project. I need to read an HTML file and then convert it to JSON format. I want to get the matches as code and text. How I achieve this? </p>
  
  <p>In this way, I have two HTML tags</p>
  
  <pre><code>&lt;p&gt;In practice, it is usually a bad idea to modify global variables inside the function scope since it often is the cause of confusion and weird errors that are hard to debug.&lt;br /&gt;
  If you want to modify a global variable via a function, it is recommended to pass it as an argument and reassign the return-value.&lt;br /&gt;
  For example:&lt;/p&gt;
  
  &lt;pre&gt;&lt;code class="{python} language-{python}"&gt;a_var = 2
  
  def a_func(some_var):
      return 2**3
  
  a_var = a_func(a_var)
  print(a_var)
  &lt;/code&gt;&lt;/pre&gt;
  </code></pre>
  
  <p>mycode:</p>
  
  <pre><code>const fs = require('fs')
  const showdown  = require('showdown')
  
  var read =  fs.readFileSync('./test.md', 'utf8')
  
  function importer(mdFile) {
  
      var result = []
      let json = {}
  
      var converter = new showdown.Converter()
      var text      = mdFile
      var html      = converter.makeHtml(text);
  
      for (var i = 0; i &lt; html.length; i++) {
          htmlRead = html[i]
          if(html == html.match(/&lt;p&gt;(.*?)&lt;\/p&gt;/g))
              json.text = html.match(/&lt;p&gt;(.*?)&lt;\/p&gt;/g)
  
         if(html == html.match(/&lt;pre&gt;(.*?)&lt;\/pre&gt;/g))
              json.code = html.match(/&lt;pre&gt;(.*?)&lt;\/pre&gt;/g
  
      }
  
      return html
  }
  console.log(importer(read))
  </code></pre>
  
  <p>How do I get these matches on the code?</p>
  
  <p>new code : I write all the p tags in the same json, how to write each p tag into different json blocks?</p>
  
  <pre><code>$('html').each(function(){
      if ($('p').text != undefined) {
          json.code = $('p').text()
          json.language = "Text"
      }
  })
  </code></pre>