0

In a lot of code written for node.js you can see something like

var debug = require('debug')('myserver:sub-bit');

The question I have, is how do I do this with import? The following does not seem to work.

var debug = (import d from 'debug')('myserver:sub-bit');

Nor have I found any other working short variations. The long approach, of course, does

import debugLib as 'debug';
var debug = debugLib('myserver:sub-bit');

But I just wanted an approach that didn't need to be broken out into two statements.

nyteshade
  • 1,973
  • 1
  • 11
  • 8
  • 1
    does `import {foo, bar} from "my-module";` fit the bill? [MDN docs](https://developer.mozilla.org/en/docs/web/javascript/reference/statements/import) – Jaromanda X Jan 22 '16 at 04:44

1 Answers1

0

My recommendation, after trying to be purist about ES6, is to use import if you're importing an ES6 module, and require() if you want to use an ES5 module. This also makes it clear from reading your code what you can expect from the external module.

kintel
  • 405
  • 2
  • 4