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
};
我得到了错误的变量addNote
,getAll
和readNote
是不是一个函数。对我来说,看起来像app.js
的变量不是从notes.js
中读取的。但"Starting notes.js"
实际上正在阅读和打印。 这里有什么问题?谢谢
非常感谢你 –
很高兴帮助。请将答案标记为已接受。 – Boney