Navigate back to the homepage

How to export multiple files in a single file in node js?

March 25th, 2022 · 1 min read
keep affilitate

Hi Friends 👋,

Welcome To Infinitbility ❤️!

Today, we will learn to export multiple files in a single file, for example, we have a lot of controller files in the node project but when I want to use any controller function then I don’t have to write also controller name.

Here, one more reason to do that way because in future when move one function to another controller then we haven’t worry about change imports also…

Let’s start today’s tutorial How to export multiple files in a single file in node js?

Now, we will create multiple sample controller files.


1const Login = () => {
2 // ...
5const Register = () => {
6 // ...
9module.exports = {
10 Login,
11 Register

We have to create one more controller


1const ViewProfile = () => {
2 // ...
5const EditProfile = () => {
6 // ...
9module.exports = {
10 ViewProfile,
11 EditProfile

After that we have to create an index file behave of all controllers, here we will register all controllers.

And when we want to use any controller function we will use from the index file.


1module.exports = {
2 ...require("./AuthController"),
3 ...require("./UserController"),

Let’s see how we can use this file in the controller. Suppose, the following is our route file.


1const { Login } = require("../Controller/index");

Here, I just provide an example to export multiple files in a single.

I Hope, You will find a solution.

All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

melio affilitate

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide



More articles from Infinitbility

How to add an image to a layer in photoshop?

Adding a custom image to a layer in photoshop example with step by step guide with images.

March 24th, 2022 · 1 min read

How to define return type of function in typescript?

TypeScript, specify the return type of function example.

March 23rd, 2022 · 1 min read
© 2020–2022 Infinitbility
Link to $ to $ to $ to $ to $ to $mailto:[email protected]