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