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

135
Views
Unable to import my notes.js when iam using node.js

this picture showing notes.js on left side and index. js on right side....how to import and export my note.js

here iam adding codes of 2 files. first one is notes.js and second one id index.js.. i dont know how to import export in newer version of node.js.here iam adding codes of 2 files. first one is notes.js and second one id index.js.. i dont know how to import export in newer version of node.js.here iam adding codes of 2 files. first one is notes.js and second one id index.js.. i dont know how to import export in newer version of node.js.here iam adding codes of 2 files. first one is notes.js and second one id index.js.. i dont know how to import export in newer version of node.jshere iam adding codes of 2 files. first one is notes.js and second one id index.js.. i dont know how to import export in newer version of node.js

//this is my nottes.js :
import fs from 'fs';

const getNotes = function(){
    return 'yours notes....'
}

const addNote = function(title,body){
    const note = loadNotes()

}

const loadNotes = function(){

    const dataBuffer = fs.readFileSync('note.json')
    const dataJson = dataBuffer.toString()
    return JSON.parse(dataJson)

}
module.exports={
    addNote:addNote,
    getNotes:getNotes
}


//this is my index.js:
import yargs from 'yargs';
import notes from './notes.js'
//const notes = require('./notes');
import {hideBin} from 'yargs/helpers';

const argv = yargs(process.argv.slice(2));
yargs(hideBin(process.argv)).command({
    command:'add',
    describe:'add a new note',
    builder:{
        title:{
            describe:"note title",
            demandOption :true,
            type:'string'
        },
        body:{
            describe:"note body",
            demandOption :true,
            type:'string'

        },
        tile:{
            describe:"note tile",
            demandOption :true,
            type:'string'

        }

    },
    handler:function(argv){
        notes.addNote(argv.title,argv.body)
    },
})

yargs(hideBin(process.argv)).command({
    command:'remove',
    describe:'removing a new note',
    handler:function(){
        console.log('removing a new note!')
    }

}).parse()

//console.log(argv.argv);
argv.parse()
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try to add the export keyword before the functions in notes.js and remove the module.exports:

export const getNotes = ...
export const addNote = ...
export const loadNotes = ...

You should then be able to import the function with

import {
    getNotes,
    addNote,
    loadNotes
} from './notes'

For more information about exporting in ES6 you can check this doc from MDN.

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!