简体   繁体   中英

Convert CJS to ES6

How can I convert these lines of code to ES6?

const basename = path.basename(__filename);
const config = require(__dirname + '/../config/config.json')[env];

You don't need to convert anything to ES6, it's perfectly valid ES6 - it just doesn't use any new features that were introduced in ES6 from my knowledge. You could use destructuring if you really wanted to:

const { env: config } = require(__dirname + "/../config/config.json");

But ES6 is not a fancy new language, it's just got some new features you can use if you need them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM