lvcpp lvcpp - 6 months ago 10
Node.js Question

Cannot GET /the route Error

I'm following this tutorial (source code) and added the highlighted code.

// app.js

app.get("/notebooks", function(req, res) {
var client = new Evernote.Client({ token: req.session.oauthAccessToken }),
noteStore = client.getNoteStore();

noteStore.listNotebooks(function(err, noteBooks) {
res.send(err || noteBooks);
});
});


app.get('/importNotes', function (req, res) {
res.send('importNotes');
});


app.get("/notes/:guid", function(req, res) {
var client = new Evernote.Client({ token: req.session.oauthAccessToken }),
noteStore = client.getNoteStore();

noteStore.getNote(req.params.guid, true, true, true, true, function(err, note) {
if (!err) {
note.content = ENML.HTMLOfENML(note.content, note.resources);
}
res.send(err || note);
});
});


another attempt:

app.get('/importNotes', function (req, res) {
res.render('importNotes', {});
});


I created importNotes.html near to index.html.

After starting the server with
node app.js


I'm getting an error stating
Cannot GET /importNotes

when I access
localhost:3000/importNotes


I plan to use this page to add additional features after I deal with this issue (import the notes from the special txt file).

What I'm doing wrong and how I can correct it?

How to define correctly the needed routes ?

Answer

This is Steve - thanks for trying out the code !

If you use this code :

app.get('/importNotes', function (req, res) {
    res.send('importNotes');
});

Then I would expect the server will send back to the browser the string "importNotes". Perhaps if you have a file called "importNotes" there is some confusion.

If you want to create a file called importNotes.html - then just put it into the "public" folder. It will then be accessible via localhost:3000/importNotes.html

The line :

app.use(express.static(__dirname + "/public"));

Tells Express to serve the contents of the "public" folder at the root level of your application, so any files you put in that folder should be GETable. e.g.

/public index.html steve.html

localhost:3000/steve.html

Comments