Can I use alias with NodeJS require function?

前端 未结 4 1339
春和景丽
春和景丽 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条回答
  •  死守一世寂寞
    2020-12-28 12:43

    Sure, just use the object destructuring syntax:

     const { old_name: new_name, foo: f, bar: b } = require('module');
    

提交回复
热议问题