Katja Durrani
@kdurrani
mail@kdurrani.co.uk
Women Who Code
Bristol
27 Jan 2015
"A development platform built on top of Google's V8 JavaScript virtual machine"
Node is popular
About 90 NodeSchools world-wide!
There are some alternative frameworks (Hapi, Koa), but so far Express is the most widely used
var express = require('express')
var app = express()
app.get('/', function (req, res) {
res.send('Hello World!')
})
var server = app.listen(3000, function () {
var host = server.address().address
var port = server.address().port
console.log('Example app listening at http://%s:%s', host, port)
})
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
Node
Express
Structure
Sub-directories for static files, views, routes, models etc.
Dependency Management
Usually via package manager (e.g. npm, bower, composer)
For npm: Dependencies listed in package.json file
npm install // installs dependencies listed in package.json
npm install <module> --save // installs new package, saves reference in package.json
Task Automation
Grunt, Gulp
Modularisation
Node uses CommonJS syntax
var React = require('react');
var App = {
[...]
}
module.exports = App
You can write node-style modules for the browser, using tools like browserify which compile them for that use
Hosting
You might have to add code to your app for it to run on specific platforms (e.g. OpenShift, AWS, Heroku)
Real-time Polls App built on MEAN stack
"A JavaScript library for building user interfaces -
the V in MVC"
Example of React Component (before and after compilation to JS)
Click to get through to the sites