SlideShare a Scribd company logo
Node.js Web App
CRASH COURSE
By Aaron Silverman, Code Slinger at Video BlocksMarch 19, 2014
Note: node.js is getting more and more popular every year!
Node.js - download and install it!
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Worldn');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
Create simple server web server
server.js
Run simple web server
$ node server.js
Server running at http://127.0.0.1:1337/
Connect to simple web server
Node.js & Twitter Bootstrap Crash Course
Why reinvent the wheel?
Packages FTW!
$ npm install -g express-generator
...
express-generator@3.0.0
/usr/local/lib/node_modules/express-generator
├── mkdirp@0.3.5
└── commander@1.3.2 (keypress@0.1.0)
Create skeleton web application
$ express --ejs myapp
...
create : myapp
...
install dependencies:
...
run the app:
Install dependencies
$ cd myapp
$ npm install
…
express@3.4.8 node_modules/express
...
Start web application
$ npm start
> application-name@0.0.1 start
/Users/aaron/Workspace/upenn/myapp
> node ./bin/www
Connect to web application
Node.js & Twitter Bootstrap Crash Course
What’s going on?
automagically created folders and files
package.json is key
started by npm start
installed by npm install
require - import/include other files
and packages
imports debug package
imports app file
what is exported
Middleware Magic
view engine
modules
middleware
routing
Route handlers
render view
View - Embedded JavaScript
view variable
Spice up our root page - route handler
exports.index = function(req, res){
res.render('index', { title: 'Express' });
res.render('index', {title: 'Express', name: 'Aaron'});
};
routes/index.js
Spice up our root page - view
<body>
<h1><%= title %></h1>
<p>Welcome to <%= title %></p>
<p>&ldquo;Welcome to <%= title %>&rdquo;</p>
<p>&mdash; <%= name %><p>
</body>
views/index.ejs
Restart and connect
$ npm start
Node.js & Twitter Bootstrap Crash Course
Internet folks love cats
Cat image
image file
Cat view
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<h1>Cat</h1>
<img src="/images/cat.jpg" />
</body>
</html>
views/cat.ejs
Cat route handler
exports.index = function(req, res) {
res.render('index', {title: 'Penn', name: 'Aaron'});
};
exports.cat = function(req, res) {
res.render('cat');
}
routes/index.js
Cat route
app.get('/', routes.index);
app.get('/users', users.list);
app.get('/cat', routes.cat);
app.js
Enough manual restarting - nodemon
$ sudo npm install -g nodemon
...
nodemon@1.0.15
…
Tell nodemon what to run
"scripts": {
"start": "node ./bin/www"
},
"main": "bin/www",
"dependencies": {
package.json
Start server using nodemon
$ nodemon
[nodemon] v1.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node bin/www`
Navigate to cat page
Node.js & Twitter Bootstrap Crash Course
Name that cat
Name that cat - route handler
exports.cat = function(req, res) {
var name = req.param('name','Mr. Cat');
res.render('cat');
res.render('cat', {name: name});
}
routes/index.js
Name that cat - view
<body>
<h1>Cat</h1>
<h1>Meet <%= name %>, the Cat.</h1>
<img src="/images/cat.jpg" />
</body>
routes/index.js
Revisit cat page
Pass name in query parameter
Node.js & Twitter Bootstrap Crash Course
Moar Cats!
Twitter Bootstrap - CSS for dummies
Bootstrap grid and components
CSS classes also makes special components
CSS class “row” starts row of a 12 column grid
CSS class “col-md-N” starts a responsive N-column wide grid element
Note: rows can be nested inside columns for a nested grid
Cat view - bootstrap css/js
<head>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css" />
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
…
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</body>
</html>
views/cat.ejs
Note: instead of using external assets we could also have downloaded and extracted these files into the
public/stylesheets and public/javscripts directories.
Cat view - name jumbotron
<body>
<div class="jumbotron">
<h1>Meet <%= name %>, the Cat.</h1>
<p>Best cat in the land</p>
</div>
views/cat.ejs
Cat view - cat grid
<div class="container cat-grid">
<div class="row">
<div class="col-md-4">
<img src="/images/cat.jpg" />
</div>
<div class="col-md-4">
...
</div>
<div class="col-md-4">
<img src="/images/cat.jpg" />
</div>
</div>
</div>
views/cat.ejs
<div class="row">
<div class="col-md-6">
<img src="/images/cat.jpg" />
</div>
<div class="col-md-6">
<img src="/images/cat.jpg" />
</div>
</div>
<div class="row">
<div class="col-md-6">
<img src="/images/cat.jpg" />
</div>
<div class="col-md-6">
<img src="/images/cat.jpg" />
</div>
</div>
Cat view - cat style
.cat-grid img {
height: 100px;
}
public/stylesheets/style.css
Moar, responsive, cats
Node.js & Twitter Bootstrap Crash Course
Module Time
Npm install and save
$ npm install --save express-partials
npm http GET https://registry.npmjs.org/express-partials
npm http 304 https://registry.npmjs.org/express-partials
express-partials@0.2.0 node_modules/express-partials
Added to package.json
newly installed package
Use new middleware
var bodyParser = require('body-parser');
var partials = require('express-partials');
var routes = require('./routes');
var users = require('./routes/user');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(partials());
app.use(favicon());
app.js
Create common view layout
views/layout.ejs
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css" />
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<%- body %>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</body>
</html>
Clean up cat view
views/cat.ejs
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css" />
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
…
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</body>
</html>
Clean up index view
views/index.ejs
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
…
</body>
</html>
Revisit Pages
$ nodemon
Node.js & Twitter Bootstrap Crash Course
How can Grandma see the cat?
Deploy on the interwebs!
Transfer code to your server
$ scp -i ~/.ssh/macbookair.pem -r myapp/ ubuntu@ec2-23-
20-153-76.compute-1.amazonaws.com:~/
Note: Ideally your code is checked into a source control repository such as git, and you would
add your server’s public key to be allowed to access to the repository.
Then you would do something like:
$ ssh -i .ssh/macbookair.pem ubuntu@ec2-23-20-153-76.compute-1.amazonaws.com
$ git clone git@github.com:Username/myapp.git
Install node.js on your server
$ ssh -i .ssh/macbookair.pem ubuntu@ec2-23-20-153-76.
compute-1.amazonaws.com
$ sudo apt-get install python-software-properties
$ sudo apt-add-repository ppa:chris-lea/node.js
$ sudo apt-get update
$ sudo apt-get install nodejs
$ node --version
v0.10.26
Install dependencies
$ cd myapp
$ npm install
Note: If you transferred your node_modules folder (such as scp did in this presentation) this won’t be
necessary. However typically that folder should be ignored by version control (e.g. in .gitignore) and you
will have to do this step.
Allow HTTP traffic for the server
Allow port forwarding to listen port
$ sudo vim /etc/sysctl.conf
(uncomment net.ipv4.ip_forward)
$ sudo sysctl -p /etc/sysctl.conf
net.ipv4.ip_forward = 1
$ sudo iptables -A PREROUTING
-t nat -i eth0 -p tcp --dport 80 -j
REDIRECT --to-port 3000
Start and connect to server
$ npm start
> application-name@0.0.1 start
/home/ubuntu/myapp
> node ./bin/www
Forever - run node as a daemon
$ sudo npm install -g forever
…
forever@0.10.11 /usr/lib/node_modules/forever
…
$ forever start bin/www
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it
does not stay up for at least 1000ms
info: Forever processing file: bin/www
Website now live forever!
Node.js & Twitter Bootstrap Crash Course

More Related Content

What's hot (20)

An Intro into webpack
An Intro into webpackAn Intro into webpack
An Intro into webpack
Squash Apps Pvt Ltd
 
Instant and offline apps with Service Worker
Instant and offline apps with Service WorkerInstant and offline apps with Service Worker
Instant and offline apps with Service Worker
Chang W. Doh
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
Greg Whalin
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
Chandrasekar G
 
Nuxt.js - Introduction
Nuxt.js - IntroductionNuxt.js - Introduction
Nuxt.js - Introduction
Sébastien Chopin
 
Nuxt Talk
Nuxt TalkNuxt Talk
Nuxt Talk
Sébastien Chopin
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
Justin Cataldo
 
Nodejs - Building a RESTful API
Nodejs - Building a RESTful APINodejs - Building a RESTful API
Nodejs - Building a RESTful API
Sang Cù
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
Yoann Gotthilf
 
ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!
Chang W. Doh
 
Testing frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTesting frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabs
Tudor Barbu
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
Ryan Anklam
 
Webpack packing it all
Webpack packing it allWebpack packing it all
Webpack packing it all
Criciúma Dev
 
Bundling your front-end with Webpack
Bundling your front-end with WebpackBundling your front-end with Webpack
Bundling your front-end with Webpack
Danillo Corvalan
 
Webpack: your final module bundler
Webpack: your final module bundlerWebpack: your final module bundler
Webpack: your final module bundler
Andrea Giannantonio
 
Production optimization with React and Webpack
Production optimization with React and WebpackProduction optimization with React and Webpack
Production optimization with React and Webpack
k88hudson
 
Javascript Bundling and modularization
Javascript Bundling and modularizationJavascript Bundling and modularization
Javascript Bundling and modularization
stbaechler
 
Web Development with NodeJS
Web Development with NodeJSWeb Development with NodeJS
Web Development with NodeJS
Riza Fahmi
 
Chrome enchanted 2015
Chrome enchanted 2015Chrome enchanted 2015
Chrome enchanted 2015
Chang W. Doh
 
Bower power
Bower powerBower power
Bower power
Eric Carlisle
 
Instant and offline apps with Service Worker
Instant and offline apps with Service WorkerInstant and offline apps with Service Worker
Instant and offline apps with Service Worker
Chang W. Doh
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
Greg Whalin
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
Justin Cataldo
 
Nodejs - Building a RESTful API
Nodejs - Building a RESTful APINodejs - Building a RESTful API
Nodejs - Building a RESTful API
Sang Cù
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
Yoann Gotthilf
 
ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!
Chang W. Doh
 
Testing frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTesting frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabs
Tudor Barbu
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
Ryan Anklam
 
Webpack packing it all
Webpack packing it allWebpack packing it all
Webpack packing it all
Criciúma Dev
 
Bundling your front-end with Webpack
Bundling your front-end with WebpackBundling your front-end with Webpack
Bundling your front-end with Webpack
Danillo Corvalan
 
Webpack: your final module bundler
Webpack: your final module bundlerWebpack: your final module bundler
Webpack: your final module bundler
Andrea Giannantonio
 
Production optimization with React and Webpack
Production optimization with React and WebpackProduction optimization with React and Webpack
Production optimization with React and Webpack
k88hudson
 
Javascript Bundling and modularization
Javascript Bundling and modularizationJavascript Bundling and modularization
Javascript Bundling and modularization
stbaechler
 
Web Development with NodeJS
Web Development with NodeJSWeb Development with NodeJS
Web Development with NodeJS
Riza Fahmi
 
Chrome enchanted 2015
Chrome enchanted 2015Chrome enchanted 2015
Chrome enchanted 2015
Chang W. Doh
 

Viewers also liked (20)

MySQL Indexing Crash Course
MySQL Indexing Crash CourseMySQL Indexing Crash Course
MySQL Indexing Crash Course
Aaron Silverman
 
Seconf2011 database driven combinatorial testing
Seconf2011   database driven combinatorial testingSeconf2011   database driven combinatorial testing
Seconf2011 database driven combinatorial testing
Aaron Silverman
 
Mongo or Die: How MongoDB Powers Doodle or Die
Mongo or Die: How MongoDB Powers Doodle or DieMongo or Die: How MongoDB Powers Doodle or Die
Mongo or Die: How MongoDB Powers Doodle or Die
Aaron Silverman
 
Npm: beyond 'npm i'
Npm: beyond 'npm i'Npm: beyond 'npm i'
Npm: beyond 'npm i'
Pieter Herroelen
 
Npm scripts
Npm scriptsNpm scripts
Npm scripts
정윤 김
 
Jaap : node, npm & grunt
Jaap : node, npm & gruntJaap : node, npm & grunt
Jaap : node, npm & grunt
Bertrand Chevrier
 
Startup JavaScript 8 - NPM, Express.JS
Startup JavaScript 8 - NPM, Express.JSStartup JavaScript 8 - NPM, Express.JS
Startup JavaScript 8 - NPM, Express.JS
Circulus
 
#7 "Многообещающий JavaScript – Promises" Денис Речкунов
#7 "Многообещающий JavaScript – Promises" Денис Речкунов#7 "Многообещающий JavaScript – Promises" Денис Речкунов
#7 "Многообещающий JavaScript – Promises" Денис Речкунов
JSib
 
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Calvin Tan
 
Node.js Crash Course
Node.js Crash CourseNode.js Crash Course
Node.js Crash Course
David Neal
 
Node.js in action
Node.js in actionNode.js in action
Node.js in action
Simon Su
 
Burgas Conf 21.06.2014 - Single page application Angularjs and Nodejs
Burgas Conf 21.06.2014 - Single page application Angularjs and NodejsBurgas Conf 21.06.2014 - Single page application Angularjs and Nodejs
Burgas Conf 21.06.2014 - Single page application Angularjs and Nodejs
Dimitar Danailov
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
Amit Thakkar
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
Chris Cowan
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJS
Hüseyin BABAL
 
Nodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsNodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web Applications
Ganesh Iyer
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs
Irfan Maulana
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
Debugging node in prod
Debugging node in prodDebugging node in prod
Debugging node in prod
Yunong Xiao
 
MySQL Indexing Crash Course
MySQL Indexing Crash CourseMySQL Indexing Crash Course
MySQL Indexing Crash Course
Aaron Silverman
 
Seconf2011 database driven combinatorial testing
Seconf2011   database driven combinatorial testingSeconf2011   database driven combinatorial testing
Seconf2011 database driven combinatorial testing
Aaron Silverman
 
Mongo or Die: How MongoDB Powers Doodle or Die
Mongo or Die: How MongoDB Powers Doodle or DieMongo or Die: How MongoDB Powers Doodle or Die
Mongo or Die: How MongoDB Powers Doodle or Die
Aaron Silverman
 
Startup JavaScript 8 - NPM, Express.JS
Startup JavaScript 8 - NPM, Express.JSStartup JavaScript 8 - NPM, Express.JS
Startup JavaScript 8 - NPM, Express.JS
Circulus
 
#7 "Многообещающий JavaScript – Promises" Денис Речкунов
#7 "Многообещающий JavaScript – Promises" Денис Речкунов#7 "Многообещающий JavaScript – Promises" Денис Речкунов
#7 "Многообещающий JavaScript – Promises" Денис Речкунов
JSib
 
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Why Node, Express and Postgres - presented 23 Feb 15, Talkjs, Microsoft Audit...
Calvin Tan
 
Node.js Crash Course
Node.js Crash CourseNode.js Crash Course
Node.js Crash Course
David Neal
 
Node.js in action
Node.js in actionNode.js in action
Node.js in action
Simon Su
 
Burgas Conf 21.06.2014 - Single page application Angularjs and Nodejs
Burgas Conf 21.06.2014 - Single page application Angularjs and NodejsBurgas Conf 21.06.2014 - Single page application Angularjs and Nodejs
Burgas Conf 21.06.2014 - Single page application Angularjs and Nodejs
Dimitar Danailov
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
Amit Thakkar
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
Chris Cowan
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJS
Hüseyin BABAL
 
Nodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsNodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web Applications
Ganesh Iyer
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs
Irfan Maulana
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
Debugging node in prod
Debugging node in prodDebugging node in prod
Debugging node in prod
Yunong Xiao
 

Similar to Node.js & Twitter Bootstrap Crash Course (20)

Death of a Themer
Death of a ThemerDeath of a Themer
Death of a Themer
James Panton
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
Adam Tomat
 
20190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React201920190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React2019
Makoto Mori
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 
Vue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerVue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue router
Katy Slemon
 
Please dont touch-3.6-jsday
Please dont touch-3.6-jsdayPlease dont touch-3.6-jsday
Please dont touch-3.6-jsday
Francesco Fullone
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
taggg
 
Refresh Austin - Intro to Dexy
Refresh Austin - Intro to DexyRefresh Austin - Intro to Dexy
Refresh Austin - Intro to Dexy
ananelson
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
Creating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web ComponentsCreating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web Components
Rachael L Moore
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 
以Vue開發電子商務網站
架構與眉角
以Vue開發電子商務網站
架構與眉角以Vue開發電子商務網站
架構與眉角
以Vue開發電子商務網站
架構與眉角
Mei-yu Chen
 
How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic template
vathur
 
Rails + Sencha = Netzke
Rails + Sencha = NetzkeRails + Sencha = Netzke
Rails + Sencha = Netzke
beffa
 
JavaScript Perfomance
JavaScript PerfomanceJavaScript Perfomance
JavaScript Perfomance
Anatol Alizar
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
Steve Souders
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
David Ličen
 
Sanjeev ghai 12
Sanjeev ghai 12Sanjeev ghai 12
Sanjeev ghai 12
Praveen kumar
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
Siarzh Miadzvedzeu
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
Daniel Cukier
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
Adam Tomat
 
20190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React201920190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React2019
Makoto Mori
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 
Vue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerVue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue router
Katy Slemon
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
taggg
 
Refresh Austin - Intro to Dexy
Refresh Austin - Intro to DexyRefresh Austin - Intro to Dexy
Refresh Austin - Intro to Dexy
ananelson
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
Creating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web ComponentsCreating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web Components
Rachael L Moore
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 
以Vue開發電子商務網站
架構與眉角
以Vue開發電子商務網站
架構與眉角以Vue開發電子商務網站
架構與眉角
以Vue開發電子商務網站
架構與眉角
Mei-yu Chen
 
How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic template
vathur
 
Rails + Sencha = Netzke
Rails + Sencha = NetzkeRails + Sencha = Netzke
Rails + Sencha = Netzke
beffa
 
JavaScript Perfomance
JavaScript PerfomanceJavaScript Perfomance
JavaScript Perfomance
Anatol Alizar
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
Steve Souders
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
David Ličen
 

Recently uploaded (20)

A11y Webinar Series - Level Up Your Accessibility Game_ A11y Audit, WCAG, and...
A11y Webinar Series - Level Up Your Accessibility Game_ A11y Audit, WCAG, and...A11y Webinar Series - Level Up Your Accessibility Game_ A11y Audit, WCAG, and...
A11y Webinar Series - Level Up Your Accessibility Game_ A11y Audit, WCAG, and...
Julia Undeutsch
 
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your UsersAutomation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Lynda Kane
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko
Fwdays
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
 
A11y Webinar Series - Level Up Your Accessibility Game_ A11y Audit, WCAG, and...
A11y Webinar Series - Level Up Your Accessibility Game_ A11y Audit, WCAG, and...A11y Webinar Series - Level Up Your Accessibility Game_ A11y Audit, WCAG, and...
A11y Webinar Series - Level Up Your Accessibility Game_ A11y Audit, WCAG, and...
Julia Undeutsch
 
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your UsersAutomation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Lynda Kane
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko
Fwdays
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
 

Node.js & Twitter Bootstrap Crash Course

  • 1. Node.js Web App CRASH COURSE By Aaron Silverman, Code Slinger at Video BlocksMarch 19, 2014
  • 2. Note: node.js is getting more and more popular every year! Node.js - download and install it!
  • 3. var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/'); Create simple server web server server.js
  • 4. Run simple web server $ node server.js Server running at http://127.0.0.1:1337/
  • 5. Connect to simple web server
  • 7. Why reinvent the wheel? Packages FTW! $ npm install -g express-generator ... [email protected] /usr/local/lib/node_modules/express-generator ├── [email protected] └── [email protected] ([email protected])
  • 8. Create skeleton web application $ express --ejs myapp ... create : myapp ... install dependencies: ... run the app:
  • 9. Install dependencies $ cd myapp $ npm install … [email protected] node_modules/express ...
  • 10. Start web application $ npm start > [email protected] start /Users/aaron/Workspace/upenn/myapp > node ./bin/www
  • 11. Connect to web application
  • 13. What’s going on? automagically created folders and files
  • 14. package.json is key started by npm start installed by npm install
  • 15. require - import/include other files and packages imports debug package imports app file what is exported
  • 18. View - Embedded JavaScript view variable
  • 19. Spice up our root page - route handler exports.index = function(req, res){ res.render('index', { title: 'Express' }); res.render('index', {title: 'Express', name: 'Aaron'}); }; routes/index.js
  • 20. Spice up our root page - view <body> <h1><%= title %></h1> <p>Welcome to <%= title %></p> <p>&ldquo;Welcome to <%= title %>&rdquo;</p> <p>&mdash; <%= name %><p> </body> views/index.ejs
  • 25. Cat view <!DOCTYPE html> <html> <head> <link rel='stylesheet' href='/stylesheets/style.css' /> </head> <body> <h1>Cat</h1> <img src="/images/cat.jpg" /> </body> </html> views/cat.ejs
  • 26. Cat route handler exports.index = function(req, res) { res.render('index', {title: 'Penn', name: 'Aaron'}); }; exports.cat = function(req, res) { res.render('cat'); } routes/index.js
  • 27. Cat route app.get('/', routes.index); app.get('/users', users.list); app.get('/cat', routes.cat); app.js
  • 28. Enough manual restarting - nodemon $ sudo npm install -g nodemon ... [email protected]
  • 29. Tell nodemon what to run "scripts": { "start": "node ./bin/www" }, "main": "bin/www", "dependencies": { package.json
  • 30. Start server using nodemon $ nodemon [nodemon] v1.0.15 [nodemon] to restart at any time, enter `rs` [nodemon] watching: *.* [nodemon] starting `node bin/www`
  • 34. Name that cat - route handler exports.cat = function(req, res) { var name = req.param('name','Mr. Cat'); res.render('cat'); res.render('cat', {name: name}); } routes/index.js
  • 35. Name that cat - view <body> <h1>Cat</h1> <h1>Meet <%= name %>, the Cat.</h1> <img src="/images/cat.jpg" /> </body> routes/index.js
  • 37. Pass name in query parameter
  • 40. Twitter Bootstrap - CSS for dummies
  • 41. Bootstrap grid and components CSS classes also makes special components CSS class “row” starts row of a 12 column grid CSS class “col-md-N” starts a responsive N-column wide grid element Note: rows can be nested inside columns for a nested grid
  • 42. Cat view - bootstrap css/js <head> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" /> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css" /> <link rel='stylesheet' href='/stylesheets/style.css' /> </head> … <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> </body> </html> views/cat.ejs Note: instead of using external assets we could also have downloaded and extracted these files into the public/stylesheets and public/javscripts directories.
  • 43. Cat view - name jumbotron <body> <div class="jumbotron"> <h1>Meet <%= name %>, the Cat.</h1> <p>Best cat in the land</p> </div> views/cat.ejs
  • 44. Cat view - cat grid <div class="container cat-grid"> <div class="row"> <div class="col-md-4"> <img src="/images/cat.jpg" /> </div> <div class="col-md-4"> ... </div> <div class="col-md-4"> <img src="/images/cat.jpg" /> </div> </div> </div> views/cat.ejs <div class="row"> <div class="col-md-6"> <img src="/images/cat.jpg" /> </div> <div class="col-md-6"> <img src="/images/cat.jpg" /> </div> </div> <div class="row"> <div class="col-md-6"> <img src="/images/cat.jpg" /> </div> <div class="col-md-6"> <img src="/images/cat.jpg" /> </div> </div>
  • 45. Cat view - cat style .cat-grid img { height: 100px; } public/stylesheets/style.css
  • 49. Npm install and save $ npm install --save express-partials npm http GET https://registry.npmjs.org/express-partials npm http 304 https://registry.npmjs.org/express-partials [email protected] node_modules/express-partials
  • 50. Added to package.json newly installed package
  • 51. Use new middleware var bodyParser = require('body-parser'); var partials = require('express-partials'); var routes = require('./routes'); var users = require('./routes/user'); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); app.use(partials()); app.use(favicon()); app.js
  • 52. Create common view layout views/layout.ejs <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" /> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css" /> <link rel='stylesheet' href='/stylesheets/style.css' /> </head> <body> <%- body %> <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> </body> </html>
  • 53. Clean up cat view views/cat.ejs <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" /> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css" /> <link rel='stylesheet' href='/stylesheets/style.css' /> </head> <body> … <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> </body> </html>
  • 54. Clean up index view views/index.ejs <!DOCTYPE html> <html> <head> <title><%= title %></title> <link rel='stylesheet' href='/stylesheets/style.css' /> </head> <body> … </body> </html>
  • 57. How can Grandma see the cat?
  • 58. Deploy on the interwebs!
  • 59. Transfer code to your server $ scp -i ~/.ssh/macbookair.pem -r myapp/ ubuntu@ec2-23- 20-153-76.compute-1.amazonaws.com:~/ Note: Ideally your code is checked into a source control repository such as git, and you would add your server’s public key to be allowed to access to the repository. Then you would do something like: $ ssh -i .ssh/macbookair.pem [email protected] $ git clone [email protected]:Username/myapp.git
  • 60. Install node.js on your server $ ssh -i .ssh/macbookair.pem ubuntu@ec2-23-20-153-76. compute-1.amazonaws.com $ sudo apt-get install python-software-properties $ sudo apt-add-repository ppa:chris-lea/node.js $ sudo apt-get update $ sudo apt-get install nodejs $ node --version v0.10.26
  • 61. Install dependencies $ cd myapp $ npm install Note: If you transferred your node_modules folder (such as scp did in this presentation) this won’t be necessary. However typically that folder should be ignored by version control (e.g. in .gitignore) and you will have to do this step.
  • 62. Allow HTTP traffic for the server
  • 63. Allow port forwarding to listen port $ sudo vim /etc/sysctl.conf (uncomment net.ipv4.ip_forward) $ sudo sysctl -p /etc/sysctl.conf net.ipv4.ip_forward = 1 $ sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
  • 64. Start and connect to server $ npm start > [email protected] start /home/ubuntu/myapp > node ./bin/www
  • 65. Forever - run node as a daemon $ sudo npm install -g forever … [email protected] /usr/lib/node_modules/forever … $ forever start bin/www warn: --minUptime not set. Defaulting to: 1000ms warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms info: Forever processing file: bin/www
  • 66. Website now live forever!