2017-05-22 20 views
0

Node.jsのチュートリアルに続いて、エラーが表示されます。Node.js:入力エラー:Notes.addNoteが関数ではありません

app.js:

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'); 
} 

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 
}; 

私は、変数addNotegetAllreadNoteが関数ではないというエラーが発生します。私にとっては、app.jsの変数はnotes.jsから読み取られていないようです。しかし、実際には"Starting notes.js"が読み込まれて印刷されています。 ここで何が問題になりますか?ありがとう

答えて

1

タイプミスがあります。 module.exportsである必要があります。

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

ありがとうございました –

+0

喜んで助けてください。回答を受け入れたものとしてマークしてください。 – Boney

関連する問題