Try this in your code:

import Foo from './Foo';
import Bar from './Bar';

// without default
export {
  Foo,
  Bar,
}

Btw, you can also do it this way:

// bundle.js
export { default as Foo } from './Foo'
export { default as Bar } from './Bar'
export { default } from './Baz'

// and import somewhere..
import Baz, { Foo, Bar } from './bundle'

Using export

export const MyFunction = () => {}
export const MyFunction2 = () => {}

const Var = 1;
const Var2 = 2;

export {
   Var,
   Var2,
}


// Then import it this way
import {
  MyFunction,
  MyFunction2,
  Var,
  Var2,
} from './foo-bar-baz';

The difference with export default is that you can export something, and apply the name where you import it:

// export default
export default class UserClass {
  constructor() {}
};

// import it
import User from './user'
Answer from webdeb on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › export
export - JavaScript - MDN Web Docs
// Exporting declarations export let name1, name2/*, … */; // also var export const name1 = 1, name2 = 2/*, … */; // also var, let export function functionName() { /* … */ } export class ClassName { /* … */ } export function* generatorFunctionName() { /* …
Top answer
1 of 8
382

Try this in your code:

import Foo from './Foo';
import Bar from './Bar';

// without default
export {
  Foo,
  Bar,
}

Btw, you can also do it this way:

// bundle.js
export { default as Foo } from './Foo'
export { default as Bar } from './Bar'
export { default } from './Baz'

// and import somewhere..
import Baz, { Foo, Bar } from './bundle'

Using export

export const MyFunction = () => {}
export const MyFunction2 = () => {}

const Var = 1;
const Var2 = 2;

export {
   Var,
   Var2,
}


// Then import it this way
import {
  MyFunction,
  MyFunction2,
  Var,
  Var2,
} from './foo-bar-baz';

The difference with export default is that you can export something, and apply the name where you import it:

// export default
export default class UserClass {
  constructor() {}
};

// import it
import User from './user'
2 of 8
26

Hope this helps:

// Export (file name: my-functions.js)
export const MyFunction1 = () => {}
export const MyFunction2 = () => {}
export const MyFunction3 = () => {}

// if using `eslint` (airbnb) then you will see warning, so do this:
const MyFunction1 = () => {}
const MyFunction2 = () => {}
const MyFunction3 = () => {}

export {MyFunction1, MyFunction2, MyFunction3};

// Import
import * as myFns from "./my-functions";

myFns.MyFunction1();
myFns.MyFunction2();
myFns.MyFunction3();


// OR Import it as Destructured
import { MyFunction1, MyFunction2, MyFunction3 } from "./my-functions";

// AND you can use it like below with brackets (Parentheses) if it's a function 
// AND without brackets if it's not function (eg. variables, Objects or Arrays)  
MyFunction1();
MyFunction2();
Discussions

node.js - Nodejs: How to export multiple objects? - Stack Overflow
I'm new to Nodejs. How to export multiple objects? More on stackoverflow.com
🌐 stackoverflow.com
Can I export more than one object using module.exports?
Question Can I export more than one object using module.exports? Answer We can export more than one object using module.exports by giving the object we export properties that are assigned to objects, a few examples: Creating an object to export where the properties are assigned to other objects: ... More on discuss.codecademy.com
🌐 discuss.codecademy.com
0
5
November 28, 2018
How to export and import multiple objects from the same file with JavaScript? - Stack Overflow
I have a file with 3 objects, and I want to import each object in a different file. const object1 { s1: { title: "placeholder title", description: "placeholder description" ... More on stackoverflow.com
🌐 stackoverflow.com
javascript - exporting multiple objects in Node.JS - Stack Overflow
I'm working on a MEAN stack project, and trying to pass a set of variables from one controller to another. My current approach is to export multiple objects for my **artworks.js** controller file: More on stackoverflow.com
🌐 stackoverflow.com
🌐
Atomizedobjects
atomizedobjects.com › blog › javascript › how-to-export-multiple-functions-in-javascript
How to export multiple functions in JavaScript | Atomized Objects
August 27, 2021 - All you have to do is apply the statement before each of your function definitions and as long as you are using JavaScript with ES6 or later which most modern projects will be, then the functions will be exported. You can use the export statement as many times as you like in a single file.
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › javascript faq
Can I export more than one object using module.exports? - JavaScript FAQ - Codecademy Forums
November 28, 2018 - Answer We can export more than one object using module.exports by giving the object we export properties that are assigned to objects, a few examples: Creating an object to export where the properties are assigned to other objects: let MainObject ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-export-multiple-values-or-elements-in-a-module
How to export multiple values or elements in a Module ? - GeeksforGeeks
June 18, 2024 - Exporting multiple values from a Node.js module can be done in various ways, each with its own advantages. Using module.exports to export an object is the most common and flexible approach, but you can also use the exports object for individual exports or mix both methods.
Find elsewhere
🌐
John Kavanagh
johnkavanagh.co.uk › home › articles › multiple named exports in one javascript file
Multiple Named Exports in One JavaScript File | John Kavanagh
August 16, 2022 - If you're working with multiple named exports out of a single JavaScript file, you can handle that by exporting each class as you create it.
🌐
YouTube
youtube.com › watch
Exporting Multiple JavaScript Functions from a Node Module - YouTube
We are going to build on our last tutorial and look at how you can export more than one item from a node module. This is done using an object.For more resour...
Published   January 30, 2019
🌐
Ronald James
ronaldjamesgroup.com › article › exporting-multiple-items-from-a-module
Exporting Multiple Items From A Module | Ronald James
Exporting Multiple Items From A Module Last week we created our first module count.js for counting items in an array. To make it a module, all we did was to assign the main function to&nb...
Top answer
1 of 7
35

This is the way I create modules:

myModule.js

var MyObject = function() {

    // This is private because it is not being return
    var _privateFunction = function(param1, param2) {
        ...
        return;
    }

    var function1 = function(param1, callback) {
        ...
        callback(err, results);    
    }

    var function2 = function(param1, param2, callback) {
        ...
        callback(err, results);    
    }

    return {
        function1: function1
       ,function2: function2
    }
}();

module.exports = MyObject;

And to use this module in another JS file, you can simply use require and use your object as normal:

someFile.js

var myObject = require('myModule');

myObject.function1(param1, function(err, result) { 
    ...
});
2 of 7
11

Of course you can. In my example I use obj to hold my config info. I put it in a file called index.js in config folder. This makes the index the preferred choice to be picked when I import 'config'. I have 2 exports here one for my node and api stuff and the other for my db. You can ignore the first bit where I set the environment.

const environment = {
  development: {
    isProduction: false
  },
  production: {
    isProduction: true
  }
}[ process.env.NODE_ENV || 'development' ];

export default Object.assign({
  host: 'localhost',
  port: '3000',
  remoteApi: {
    token: {
      'X-Token': '222222222222222222'
    },
    base: 'https://www.somedomain.com/api'
  }
}, environment);

export const db = {
  dbHost: 'localhost',
  dbPort: 176178
};

Calling import config from '../config'; will pick the default one. And if I specify I can get the db export import { db } from '../config';

🌐
Codingem
codingem.com › home › how to export multiple functions in javascript
How to Export Multiple Functions in JavaScript - codingem.com
July 10, 2025 - To export multiple functions in JavaScript, use the export statement and export the functions as an object.
🌐
Softwareshorts
softwareshorts.com › how-to-export-multiple-functions-in-javascript
How to export multiple functions in JavaScript | SoftwareShorts
1const add = (a, b) => a + b; 2const multiply = (a, b) => a * b; 3const divide = (a, b) => a / b; 4 5export { add, multiply, divide }; And lastly, if you cannot use ES6 then you can use module.exports like so:
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › modules
Export and Import
Modules that declare a single entity, e.g. a module user.js exports only class User.
🌐
DhiWise
dhiwise.com › post › what-you-need-to-know-about-named-exports-in-javascript
The Ultimate Guide to Named Exports: All You Need to Know
September 15, 2023 - In conclusion, named exports are a fundamental part of JavaScript modules, providing a flexible way to export multiple values from a module. They play a significant role in code organization, allowing us to export and import multiple values, including functions, objects, components, hooks, and contexts.
🌐
DhiWise
dhiwise.com › post › the-ultimate-guide-to-react-export-multiple-functions
React Export Multiple Functions
October 22, 2024 - A default export can be imported without curly braces and is typically used for the main functionality of the js file. In contrast, named exports allow for as many named exports as needed, providing flexibility when you have to export multiple components or functions from a single module.