Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
How to import functions javascript

i need to export my functions from index.js

And use it in app.js like myFunction() Dont var.myFunction() And whithout using

{myFunction} = require("index.js")

Because i need import them all

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Assign all functions in index.js to module.exports

for example , below content in your index.js

module.exports= { t: x=> console.log ('this is '+x), add: (x,y) => x+y}

to import them use

const myFunctions =require('index.js')

and then you can call myFunctions.add(2,3)

To learn more check module.exports in : https://learnjsx.com/category/2/posts/es6-moduleExports

about 4 years ago · Juan Pablo Isaza Report

0

Please learn more about the CommonJS module specification.

https://flaviocopes.com/commonjs/

Let's assume we have util.js.

exports.one = () => {}
exports.two = () => {}
exports.three = () => {}

Then as I know we can import everything like this.

const Util = require('utils.js');

Util.one()
Util.two()
Util.three()

Using ES6 syntax

import * as Util from 'utils.js'

Hope that answers your question.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!