Originally posted here on YouTube.
(Give me a thumbs up and subscribe if you found this useful 🙏).
Using modules in Node.js or other applications of JavaScript can be very useful to create more maintainable and reusable code.
In this tutorial we'll look at how to import and export modules in Node.js.
We'll start off by taking a look at how to export a function using the module.exports syntax and then import it into another file by using the JavaScript require keyword.
This is the standard way of doing it but we'll also take a look at using the Babel transpiler to convert newer code using the JavaScript import and JavaScript export keywords into older code that can be used by Node.js.
With this second approach, rather than using module.exports and the require keyword, we can simply use the more descriptive and appropriate JavaScript import and export keywords which makes life a little easier.
Top comments (0)