Sunday 21 May 2017

Node.js: Typing error: Notes.addNote is not a function

Following a tutorial on Node.js, get an error.

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

I get the error that variables addNote, getAll and readNote are not a function. To me it looks like variables from app.js are not being read from notes.js. But the "Starting notes.js" is actually being read and printed. What could be the problem here? Thanks



via Ion L

No comments:

Post a Comment