CodeNewbie Community 🌱

Cover image for Node.js 10 Is Being End-of-Lifed Today, but What Does It All Mean?
Alex Lakatos πŸ₯‘πŸ‡¬πŸ‡§
Alex Lakatos πŸ₯‘πŸ‡¬πŸ‡§

Posted on • Originally published at dev.to

Node.js 10 Is Being End-of-Lifed Today, but What Does It All Mean?

Any Node.js end-of-life day is a good day, but today especially so! Node.js v10 is being end-of-lifed today, so you can finally support ES6 imports in your JavaScript code examples and libraries by default!

The latest versions of Node.js v12 (not the earlier versions, mind you) support ES6 modules by default, so there is no need to do the ugly hacks you needed to do before if you wanted to write modern JavaScript.

Before

Before, you had to save your code a .mjs instead of js, and then run node with the --experimental-modules flag. Which most Node.js runtimes online were very slow to adopt.

$ node --experimental-modules index.mjs

After

The latest versions of Node.js v12+ support this out of the box, so there is no need to run with a flag. And most Node.js runtimes update to the latest Maintenance release, so they support it as well.

If you want to run on your own hosted environment now you can either:

  • save the file with a .mjs extension, and run it regularly with node index.mjs
  • save the file with a regular .js extension, add type: module to your package.json file, and then run the file regularly with node index.js

Changing Old Code

If you're migrating from the old require to the more modern import, there are a couple of things you'll need to do to your files:

  • change module.exports = avocados into export default avocados
  • change const avocados = require('avocados') into import avocados from 'avocados'

Most IDEs account for this and help you change it. Like VS Code.

If you want to see it in action on a slightly bigger project, I've switched over the Fidel sample application using things like express, dotenv and axios a little while back, it's all contained in a commit thought so easy to see the changes.

Wait, What is End-of-Life?

"End-of-life" or EOL is a term used by older, more enterprise-focused companies, to let everyone know that they're limiting support or outright not supporting a certain version of their product anymore. You could say the OpenJS Foundation has "pulled the plug" on Node.js v10. πŸ˜…

Got Love?

If you've loved the pun at the end, or if you just found this mildly useful, please consider following me on Twitter. I'd be storked. πŸ˜…

Top comments (0)