2017-05-22 1 views
0

Node.js에 대한 학습서를 읽으면 오류가 발생합니다. Node.js : 입력 오류 : Notes.addNote가 함수가 아닙니다.

notes.js:

console.log('Starting notes.js'); 

var addNote = function (title, body) { 
    console.log ('Adding note', title, body); 
}; 

var getAll =() => { 
    console.log ("getting all notes"); 
}; 

var readNote = function(title) { 
    console.log("I am reading note", title); 
} 

module.export = { 
    addNote, 
    getAll, 
    readNote 
}; 

console.log('Starting app.js'); 

const fs = require('fs'); 
const _ = require ('lodash'); 
const yargs = require('yargs'); 

const notes = require ('./notes.js'); 

const argv = yargs.argv; 

var command = process.argv[2]; 
console.log ('Command:' , command); 
console.log ('Process: ', process.argv); 
console.log('Yargs: ', argv) 
if (command === 'add') { 
    notes.addNote (argv.title, argv.body); 
} 
else if (command === 'list') { 
    notes.getAll(); 
} 
else if (command === 'read') { 
    notes.readNote(argv.title); 
} 
else if (command === 'delete') { 
    console.log ('command deleted'); 
} 
else { 
    console.log('command not recognized'); 
} 

app.js:

나는 변수 addNote, getAllreadNote 함수가 아니라는 오류가 발생합니다. 내게는 app.js의 변수가 notes.js에서 읽지 않은 것 같습니다. 그러나 "Starting notes.js"은 실제로 읽고 인쇄됩니다. 여기에 무슨 문제가있을 수 있습니까? 감사합니다

답변

1

오타가 있습니다. module.exports이어야합니다.

module.exports = { 
    addNote, 
    getAll, 
    readNote 
}; 
+0

대단히 감사합니다. –

+0

도움을 주셔서 감사합니다. 답변을 수락 된 것으로 표시하십시오. – Boney

관련 문제