By: Matthew Poulson
For about a month
"It is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices."
https://nodejs.org/
Node Approved for Web Application Service Layer
https://www.talentbuddy.co/blog/building-with-node-js/
https://www.talentbuddy.co/blog/building-with-node-js-at-linkedin/
https://www.talentbuddy.co/blog/building-with-node-js-at-netflix/
https://www.talentbuddy.co/blog/building-with-node-js-at-the-new-york-times/
https://www.talentbuddy.co/blog/on-building-with-node-js-at-medium-and-growing-as-a-developer/
npm set registry http://icsnpm.ldschurch.org/
$ npm install -g generator-lds-node
Request & Response
Middleware
Modules
Templates
Routes
Request & Response
Middleware
Modules
Templates
Routes
router.get('/', function(request, response) {
response.render('index', {
title: 'test'
});
});
Middleware
Modules
Templates
Routes
Request & Response
router.get('/:name', function(request, response) {
var name = request.params.name;
response.render('index', {
username: name
});
});
// path: '/tom',
// name = tom
Middleware
Modules
Templates
Routes
Request & Response
response.render('index', {
title: 'test'
});
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel="stylesheet" href="styles/style.css" />
</head>
<body>
<div>
Hello World, this is the
<%= title %> project
</div>
<script src="scripts/test.js"></script>
</body>
</html>
Middleware
Modules
Templates
Routes
Request & Response
Functions that receive and modify the Request & Response objects
Middleware
Modules
Templates
Routes
Request & Response
next() or response.end()
Middleware
Modules
Templates
Routes
Request & Response
app.use(json());
app.use(urlencoded({
extended: true
}));
app.use(helmet.xframe('deny'));
app.use(helmet.csp({
'default-src': ["'self'", '*.ldscdn.org']
, styleSrc: ["'self'", "'unsafe-inline'", '*.ldscdn.org']
}));
app.use(helmet.xssFilter());
app.disable('x-powered-by');
app.use(wam());
app.use(express.static(path.join(__dirname, 'public')));
Middleware
Modules
Templates
Routes
Request & Response
// /routes/index.js
//Stuff it Requires
var router = require('express').Router();
//Stuff it Does
router.get('/', function(request, response) {
console.log('The req object:', request);
response.render('index', {
title: 'test'
});
});
//Stuff it Exports
module.exports = router;
Middleware
Modules
Templates
Routes
Request & Response
function sluggify (title) {
var slug = encodeURIComponent(title.replace(/\s/g, '-')
.replace(/&/, 'and')
.replace(/\W+/, '')
.toLowerCase());
return slug;
}
module.exports = sluggify;
Module Example
Middleware
Modules
Templates
Routes
Request & Response
Middleware
Modules
Templates
Routes
Request & Response
Installs the module in your node_modules directory
Middleware
Modules
Templates
Routes
Request & Response
Installs the module globally
Middleware
Modules
Templates
Routes
Request & Response
Installs the module in your node_modules directory and adds it to your package.json under dependencies
Middleware
Modules
Templates
Routes
Request & Response
Installs the module in your node_modules directory and adds it to your package.json under devDependencies
Middleware
Modules
Templates
Routes
Request & Response
Installs all of the modules listed as a dependency or dev dependency in your package.json
Middleware
Modules
Templates
Routes
Request & Response
require('<package name>')
Loads the named module
// npm module
express = require('express'),
// local module
routes = require('./routes'),
Middleware
Modules
Templates
Routes
Request & Response
Is a real boy