If you are lacking any of these things, just follow along closely and you'll probably pick them up along the way.
If you ever get behind, we provided milestones in the download - use them to catch up until someone can help you.
Node.js is a platform which lets JavaScript be used for server-side development. People like it because:
By the end of today:
By the end of tomorrow:
Short enough to put on a slide:
var express = require('express');
var app = express();
app.set('port', process.env.PORT || 3000);
app.get('/', function(req, res) {
return res.send('hello world!');
});
// Start listening for requests
app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});
Let's run it.
We'll add:
Let's look at an example template and talk about the Mustache parts.
npm install --save hjs
Lots of Node packages exist in the form of a middleware. We're going to add a few for:
Later, we'll use middlewares which help us:
We'll also write some middleware functions of our own.
Goals:
A user visiting a webpage is said to have a session with that site; usually a cookie keeps track of this to keep you logged in, or to remember your shopping cart.
We're going to:
Express lets us combine multiple routes into one router, then mount that router somewhere. We're going to:
This won't change or add any functionality, but it'll be useful as the app grows.
Now we will add:
A functional form is made up of two main parts:
We'll add a form to our index template for the former, and we'll add router.post('/create', ...)
to our routes for the latter.
Now we have the notes, so we just need to display them. Two parts to this:
Now we're just going to move each note to its own separate page. We need to:
They work something like this:
router.get('/:id', function(req, res) {
return res.send(req.params.id);
});
They let us capture variables out of a URL path and use them to make decisions in the logic of our application. We'll use this to give each note its own linkable page.
We're going to build on this tomorrow to integrate with APIs, authentication, and a database.