O'Reilly logo

Node Web Development - Second Edition by David Herron

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating the Notes application code

Let's start, as before, with the express command line tool:

$ express --ejs notes
.. instructions
$ cd notes
$ npm install
.. output
$ ls
app.js node_modules package.json public routes views

If you wish, you can run node app to view the blank application in your browser. But instead, let's move on to setting up the code.

The Notes model

Create a directory named models, as a sibling of the views and routes directories. Then create a file named notes.js in that directory, with this code:

var notes = [];
exports.update = exports.create = function(key, title, body) { notes[key] = { title: title, body: body }; } exports.read = function(key) { return notes[key]; } exports.destroy = function(key) { delete notes[key]; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required