DEV Community

0 seconds of 4 minutes, 51 secondsVolume 90%
Press shift question mark to access a list of keyboard shortcuts
00:00
00:00
04:51
 
James Bubb
James Bubb

Posted on • Edited on

2

How To Import and Export Modules in Node.js Tutorial

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.

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay