Can I use alias with NodeJS require function?

前端 未结 4 1338
春和景丽
春和景丽 2020-12-28 11:49

I have an ES6 module that exports two constants:

export const foo = \"foo\";
export const bar = \"bar\";

I can do the following in another

4条回答
  •  萌比男神i
    2020-12-28 12:27

    It is possible (tested with Node 8.9.4):

    const {foo: f, bar: b} = require('module');
    console.log(`${f} ${b}`); // foo bar
    

提交回复
热议问题