2017-05-22 35 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