title: nodejs convert from import to require
body: <p>I'm getting into a case not covered in <a href="https://stackoverflow.com/questions/43353500/">How to bulk convert some javascript code from import to require?</a>. </p>
  
  <p>Here is the <a href="https://www.npmjs.com/package/hot-import" rel="nofollow noreferrer">original code from npm package <code>hot-import</code></a>:</p>
  
  <pre><code>import * as assert  from 'assert'
  import * as fs      from 'fs'
  import * as path    from 'path'
  
  import hotImport  from 'hot-import'
  </code></pre>
  
  <p>I converted them to,</p>
  
  <pre><code>const assert = require('assert')
  const fs = require('fs')
  const path = require('path')
  
  const hotImport = require('hot-import')
  const hotMod = await hotImport(MODULE_FILE)
  </code></pre>
  
  <p>but got:</p>
  
  <pre><code>TypeError: hotImport is not a function
  </code></pre>
  
  <p>After some massive trial-and-errors, I found that <code>const { hotImport } = require('hot-import')</code> works, but I have no idea why. </p>
  
  <p>Can somebody summarize, when to use <code>const hotImport = require('hot-import')</code> and when to use <code>const { hotImport } = require('hot-import')</code> please? </p>
  
  <p>And also related, why the demo code use,</p>
  
  <pre><code>import * as fs      from 'fs'
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>import fs      from 'fs'
  </code></pre>
  
  <p>? what's the differences between the two, and when to choose which? </p>