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.

Image of Timescale

๐Ÿš€ pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applicationsโ€”without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up