Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda