SlideShare a Scribd company logo
1 of 48
Download to read offline
Introduction toNode.JSFrom “Hello, World!” to Deploying on Azure#dunDDD29thNovember 2014Colin Mackayhttp://colinmackay.scot
Overview•What is node.js•Obligatory Hello, World! •Dependencies & node package manager•Web applications in node
What is node.js? Officially: Node.js®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. http://nodejs.org/
What is node.js, really? •A platform for executing JavaScript–Server-side–Modular–Non-blocking (async) code–Built-in networking, HTTP & WebSocketshttp://nodejs.org/
What are the advantages? •All running on one environment–No worries about browser compatibility–Google’s V8 Engine•ECMAScript 5 –up-to-date JS•Optimisation•JIT compiled•Non-blockinghttp://nodejs.org/
Typical StackMEAN•MongoDB(Database) •Express *(Web Framework) •Angular.js(UI Framework) •Node.js *(Platform) * This talk will introduce these topicshttp://www.mongodb.org/ http://expressjs.com/ https://angularjs.org/ http://nodejs.org/
Windows Installer•Add to PATH ensure available at any command prompt  •I wish more windows installers would do thishttp://nodejs.org/
IDEs for node.jsJetBrainsWeb StormVisual Studio Add-inhttp://nodejstools.codeplex.com/http://www.jetbrains.com/webstorm/
Hello World!
Splitting code across files•One large file would be horrible•Require(“./file.js”) •Module.exports•Can be hierarchical
DEMO #1Require & module.exports
Requiring a folder•Need a file to describe the folder–Index.js–Packages.json{ "name" : "my-library", "main" : "./lib/my-library.js" } •Exports from index/packages returned via requires
Node Package Manager•Like NuGet, but for node.js•Packages go in node_modulesfolder•Install with npminstall <name> –Add --saveto reference it in your app’s package.jsonto exclude it from source control. https://www.npmjs.org/
Package.json•JSON formatted file•Stores dependency information•npminstallto rebuild the dependencies–Useful after getting from source controlhttps://www.npmjs.org/doc/files/package.json.html
Package.json: example 
{ "name": "hello-world", "version": "0.0.1", "dependencies": { "express": "^4.10.3" } }
DEMO #2Node Package Manager
Express•Web Application Framework•Related to –Sinatra (Ruby) –Nancy (.NET) •“Fast, unopinionated, minimalist web framework for Node.js” http://expressjs.com/
Installing Express•npminstall express
Express: Hello, World! (1) // Requirementsvarexpress = require("express"); varhttp = require("http"); // Set up the applicationvarapp = express(); app.set("port", process.env.PORT|| 3000); // Run up the serverhttp.createServer(app).listen(app.get("port"), function(){ console.log("Express server listening on port " + app.get("port")); }); http://colinmackay.scot/2014/11/15/express-for-node-js-walk-through-hello-world/
Express: Hello, World! (2) module.exports= function(req, res) { res.send( "<h1>"+ "Hello, World!"+ "</h1>"); }; http://colinmackay.scot/2014/11/15/express-for-node-js-walk-through-hello-world/
Express: Hello, World! (3) •Need to add routing details to app.js•Supports most common HTTP verbs–And some uncommon onesapp.get("/", routeGetFunc); app.post("/", routePostFunc); app.put("/", routePutFunc); app.delete("/", routeDeleteFunc); http://colinmackay.scot/2014/11/15/express-for-node-js-walk-through-hello-world/
DEMO #3Express Hello World
Express IDE Support•IDE Support–VS AddInhas three templates–WebStormhas one template, but it’s more configurable.
Express Template•Express Template sets many things up for you•Completely configurable•Could throw most of this away for a basic app
Jade –View Engine
View Engines•Handlebars.js•JSHTML•Mustache/ Hogan.js•Underscore templates•Vash–Based on Razor Syntax
View Engines : EJS•EJS = Embedded JavaScript–Based on ERB (Embedded Ruby) –Similar to ASP.NET WebFormsview engine•No master page/layout support–Package for that! http://colinmackay.scot/2014/11/16/express-for-node-js-view-engines/
Static Files•Defaults to safty•Configure directories to expose•More complex rules possible 
app.use( 
express.static( 
__dirname+ '/public')); http://colinmackay.scot/2014/11/16/express-for-node-js-view-engines/
DEMO #4View Engines and Static Fileshttp://colinmackay.scot/2014/11/16/express-for-node-js-view-engines/
Processing form data•It’s a middleware–Many parsers available–Common: body-parser•Values available in req.bodyhttp://colinmackay.scot/2014/11/17/node-js-with-express-getting-form-data/
Body-parser setup & useApp.js 
varbodyParser= 
require("body-parser"); 
… 
app.use( 
bodyParser.urlencoded()); setLanguage.js 
varlanguage = req.body.language; http://colinmackay.scot/2014/11/17/node-js-with-express-getting-form-data/
Processing Cookies•Parsing cookies is middleware–Common: cookie-parser•Values available in req.cookies•Write values with res.cookie() •Clear cookie with res.clearCookie() –Much easier than .NEThttp://colinmackay.scot/2014/11/18/node-js-with-express-come-to-the-dark-side- we-have-cookies/
Cookie-parser setup & useApp.jssetLanguage.js 
varcookieParser= 
require("cookie-parser"); 
… 
app.use(cookieParser()); 
varlanguage = req.body.language; 
varcookieAge= 24*60*60*1000; // 1 day 
res.cookie( 
"flashcard-language", 
language, 
{ maxAge:cookieAge, 
httpOnly:true}); http://colinmackay.scot/2014/11/18/node-js-with-express-come-to-the-dark-side- we-have-cookies/
Cookie-parser setup & useFlashcard.jsWelcome.js 
varlanguage = 
req.cookies[ 
"flashcard-language"]; 
res.clearCookie( 
"flashcard-language"); http://colinmackay.scot/2014/11/18/node-js-with-express-come-to-the-dark-side- we-have-cookies/
DEMO #5Body & Cookie Parsinghttp://colinmackay.scot/2014/11/17/node-js-with-express-getting-form-data/ http://colinmackay.scot/2014/11/18/node-js-with-express-come-to-the-dark-side- we-have-cookies/
Deploying to Azure•Surprisingly easy–Almost…  •Deploy via source control
DEMO #6Deploying to Azurehttp://colinmackay.scot/2014/11/23/deploying-a-node-js-with-express-application- on-azure/
Deploying to Azure (1)
Deploying to Azure (2)
Deploying to Azure (3) http://colinmackay.scot/2014/11/23/deploying-a-node-js-with-express-application- on-azure/
Deploying to Azure (4) http://colinmackay.scot/2014/11/23/deploying-a-node-js-with-express-application- on-azure/
An issue with the imageshttp://colinmackay.scot/2014/11/23/deploying-a-node-js-with-express-application- on-azure/
Diagnosing the issueMissing imageMissing resource
Fixing the web.config 
<staticContent> 
<mimeMapfileExtension=".svg" mimeType="image/svg+xml" /> 
</staticContent> http://colinmackay.scot/2014/11/23/deploying-a-node-js-with-express-application- on-azure/
Finally working
Follow up information•Blog: http://colinmackay.scot/ –Slide deck available soon•Twitter: @colinmackay
Introduction to Node.JSQuestion Timehttp://colinmackay.scot/tag/node-js/
Follow up information•Blog: http://colinmackay.scot/ –Slide deck available soon•Twitter: @colinmackay

More Related Content

What's hot

What's hot (20)

Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting started
 
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaJavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
 
Node js
Node jsNode js
Node js
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
 
Node js for enterprise
Node js for enterpriseNode js for enterprise
Node js for enterprise
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
 
Node js training (1)
Node js training (1)Node js training (1)
Node js training (1)
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Introduction to node.js aka NodeJS
Introduction to node.js aka NodeJSIntroduction to node.js aka NodeJS
Introduction to node.js aka NodeJS
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7
 
Nodejs
NodejsNodejs
Nodejs
 

Viewers also liked

Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
Mohammad Qureshi
 
From Hello World to Real World - Container Days Boston 2016
From Hello World to Real World - Container Days Boston 2016From Hello World to Real World - Container Days Boston 2016
From Hello World to Real World - Container Days Boston 2016
Shannon Williams
 

Viewers also liked (20)

Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。
 
EmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image AnalysisEmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image Analysis
 
Debugging node in prod
Debugging node in prodDebugging node in prod
Debugging node in prod
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Nodejs Intro Part One
Nodejs Intro Part OneNodejs Intro Part One
Nodejs Intro Part One
 
Hello world - intro to node js
Hello world - intro to node jsHello world - intro to node js
Hello world - intro to node js
 
Node.js – ask us anything!
Node.js – ask us anything! Node.js – ask us anything!
Node.js – ask us anything!
 
Building A Web App In 100% JavaScript with Carl Bergenhem
 Building A Web App In 100% JavaScript with Carl Bergenhem Building A Web App In 100% JavaScript with Carl Bergenhem
Building A Web App In 100% JavaScript with Carl Bergenhem
 
Pengenalan Dasar NodeJS
Pengenalan Dasar NodeJSPengenalan Dasar NodeJS
Pengenalan Dasar NodeJS
 
Knonex
KnonexKnonex
Knonex
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
Node js mongodriver
Node js mongodriverNode js mongodriver
Node js mongodriver
 
Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web App
 
#7 "Многообещающий JavaScript – Promises" Денис Речкунов
#7 "Многообещающий JavaScript – Promises" Денис Речкунов#7 "Многообещающий JavaScript – Promises" Денис Речкунов
#7 "Многообещающий JavaScript – Promises" Денис Речкунов
 
From Hello World to Real World - Container Days Boston 2016
From Hello World to Real World - Container Days Boston 2016From Hello World to Real World - Container Days Boston 2016
From Hello World to Real World - Container Days Boston 2016
 
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...
 
Asynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaAsynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and Java
 

Similar to Introduction to node js - From "hello world" to deploying on azure

nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
WalaSidhom1
 

Similar to Introduction to node js - From "hello world" to deploying on azure (20)

Nodejs web,db,hosting
Nodejs web,db,hostingNodejs web,db,hosting
Nodejs web,db,hosting
 
Extending Build to the Client: A Maven User's Guide to Grunt.js
Extending Build to the Client: A Maven User's Guide to Grunt.jsExtending Build to the Client: A Maven User's Guide to Grunt.js
Extending Build to the Client: A Maven User's Guide to Grunt.js
 
Docker based Architecture by Denys Serdiuk
Docker based Architecture by Denys SerdiukDocker based Architecture by Denys Serdiuk
Docker based Architecture by Denys Serdiuk
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
An Introduction to Node.js Development with Windows Azure
An Introduction to Node.js Development with Windows AzureAn Introduction to Node.js Development with Windows Azure
An Introduction to Node.js Development with Windows Azure
 
Intro to Sails.js
Intro to Sails.jsIntro to Sails.js
Intro to Sails.js
 
The MEAN Stack
The MEAN StackThe MEAN Stack
The MEAN Stack
 
Mongo and node mongo dc 2011
Mongo and node mongo dc 2011Mongo and node mongo dc 2011
Mongo and node mongo dc 2011
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed Assaf
 
Node js (runtime environment + js library) platform
Node js (runtime environment + js library) platformNode js (runtime environment + js library) platform
Node js (runtime environment + js library) platform
 
Open shift and docker - october,2014
Open shift and docker - october,2014Open shift and docker - october,2014
Open shift and docker - october,2014
 
Short-Training asp.net vNext
Short-Training asp.net vNextShort-Training asp.net vNext
Short-Training asp.net vNext
 
Deploying windows containers with kubernetes
Deploying windows containers with kubernetesDeploying windows containers with kubernetes
Deploying windows containers with kubernetes
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA Templates
 
Introduction to Node (15th May 2017)
Introduction to Node (15th May 2017)Introduction to Node (15th May 2017)
Introduction to Node (15th May 2017)
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web Applications
 
Treinamento frontend
Treinamento frontendTreinamento frontend
Treinamento frontend
 

Recently uploaded

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Recently uploaded (20)

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 

Introduction to node js - From "hello world" to deploying on azure

  • 1. Introduction toNode.JSFrom “Hello, World!” to Deploying on Azure#dunDDD29thNovember 2014Colin Mackayhttp://colinmackay.scot
  • 2. Overview•What is node.js•Obligatory Hello, World! •Dependencies & node package manager•Web applications in node
  • 3. What is node.js? Officially: Node.js®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. http://nodejs.org/
  • 4. What is node.js, really? •A platform for executing JavaScript–Server-side–Modular–Non-blocking (async) code–Built-in networking, HTTP & WebSocketshttp://nodejs.org/
  • 5. What are the advantages? •All running on one environment–No worries about browser compatibility–Google’s V8 Engine•ECMAScript 5 –up-to-date JS•Optimisation•JIT compiled•Non-blockinghttp://nodejs.org/
  • 6. Typical StackMEAN•MongoDB(Database) •Express *(Web Framework) •Angular.js(UI Framework) •Node.js *(Platform) * This talk will introduce these topicshttp://www.mongodb.org/ http://expressjs.com/ https://angularjs.org/ http://nodejs.org/
  • 7. Windows Installer•Add to PATH ensure available at any command prompt  •I wish more windows installers would do thishttp://nodejs.org/
  • 8. IDEs for node.jsJetBrainsWeb StormVisual Studio Add-inhttp://nodejstools.codeplex.com/http://www.jetbrains.com/webstorm/
  • 10. Splitting code across files•One large file would be horrible•Require(“./file.js”) •Module.exports•Can be hierarchical
  • 11. DEMO #1Require & module.exports
  • 12. Requiring a folder•Need a file to describe the folder–Index.js–Packages.json{ "name" : "my-library", "main" : "./lib/my-library.js" } •Exports from index/packages returned via requires
  • 13. Node Package Manager•Like NuGet, but for node.js•Packages go in node_modulesfolder•Install with npminstall <name> –Add --saveto reference it in your app’s package.jsonto exclude it from source control. https://www.npmjs.org/
  • 14. Package.json•JSON formatted file•Stores dependency information•npminstallto rebuild the dependencies–Useful after getting from source controlhttps://www.npmjs.org/doc/files/package.json.html
  • 15. Package.json: example { "name": "hello-world", "version": "0.0.1", "dependencies": { "express": "^4.10.3" } }
  • 17. Express•Web Application Framework•Related to –Sinatra (Ruby) –Nancy (.NET) •“Fast, unopinionated, minimalist web framework for Node.js” http://expressjs.com/
  • 19. Express: Hello, World! (1) // Requirementsvarexpress = require("express"); varhttp = require("http"); // Set up the applicationvarapp = express(); app.set("port", process.env.PORT|| 3000); // Run up the serverhttp.createServer(app).listen(app.get("port"), function(){ console.log("Express server listening on port " + app.get("port")); }); http://colinmackay.scot/2014/11/15/express-for-node-js-walk-through-hello-world/
  • 20. Express: Hello, World! (2) module.exports= function(req, res) { res.send( "<h1>"+ "Hello, World!"+ "</h1>"); }; http://colinmackay.scot/2014/11/15/express-for-node-js-walk-through-hello-world/
  • 21. Express: Hello, World! (3) •Need to add routing details to app.js•Supports most common HTTP verbs–And some uncommon onesapp.get("/", routeGetFunc); app.post("/", routePostFunc); app.put("/", routePutFunc); app.delete("/", routeDeleteFunc); http://colinmackay.scot/2014/11/15/express-for-node-js-walk-through-hello-world/
  • 23. Express IDE Support•IDE Support–VS AddInhas three templates–WebStormhas one template, but it’s more configurable.
  • 24. Express Template•Express Template sets many things up for you•Completely configurable•Could throw most of this away for a basic app
  • 27. View Engines : EJS•EJS = Embedded JavaScript–Based on ERB (Embedded Ruby) –Similar to ASP.NET WebFormsview engine•No master page/layout support–Package for that! http://colinmackay.scot/2014/11/16/express-for-node-js-view-engines/
  • 28. Static Files•Defaults to safty•Configure directories to expose•More complex rules possible app.use( express.static( __dirname+ '/public')); http://colinmackay.scot/2014/11/16/express-for-node-js-view-engines/
  • 29. DEMO #4View Engines and Static Fileshttp://colinmackay.scot/2014/11/16/express-for-node-js-view-engines/
  • 30. Processing form data•It’s a middleware–Many parsers available–Common: body-parser•Values available in req.bodyhttp://colinmackay.scot/2014/11/17/node-js-with-express-getting-form-data/
  • 31. Body-parser setup & useApp.js varbodyParser= require("body-parser"); … app.use( bodyParser.urlencoded()); setLanguage.js varlanguage = req.body.language; http://colinmackay.scot/2014/11/17/node-js-with-express-getting-form-data/
  • 32. Processing Cookies•Parsing cookies is middleware–Common: cookie-parser•Values available in req.cookies•Write values with res.cookie() •Clear cookie with res.clearCookie() –Much easier than .NEThttp://colinmackay.scot/2014/11/18/node-js-with-express-come-to-the-dark-side- we-have-cookies/
  • 33. Cookie-parser setup & useApp.jssetLanguage.js varcookieParser= require("cookie-parser"); … app.use(cookieParser()); varlanguage = req.body.language; varcookieAge= 24*60*60*1000; // 1 day res.cookie( "flashcard-language", language, { maxAge:cookieAge, httpOnly:true}); http://colinmackay.scot/2014/11/18/node-js-with-express-come-to-the-dark-side- we-have-cookies/
  • 34. Cookie-parser setup & useFlashcard.jsWelcome.js varlanguage = req.cookies[ "flashcard-language"]; res.clearCookie( "flashcard-language"); http://colinmackay.scot/2014/11/18/node-js-with-express-come-to-the-dark-side- we-have-cookies/
  • 35. DEMO #5Body & Cookie Parsinghttp://colinmackay.scot/2014/11/17/node-js-with-express-getting-form-data/ http://colinmackay.scot/2014/11/18/node-js-with-express-come-to-the-dark-side- we-have-cookies/
  • 36. Deploying to Azure•Surprisingly easy–Almost…  •Deploy via source control
  • 37. DEMO #6Deploying to Azurehttp://colinmackay.scot/2014/11/23/deploying-a-node-js-with-express-application- on-azure/
  • 40. Deploying to Azure (3) http://colinmackay.scot/2014/11/23/deploying-a-node-js-with-express-application- on-azure/
  • 41. Deploying to Azure (4) http://colinmackay.scot/2014/11/23/deploying-a-node-js-with-express-application- on-azure/
  • 42. An issue with the imageshttp://colinmackay.scot/2014/11/23/deploying-a-node-js-with-express-application- on-azure/
  • 43. Diagnosing the issueMissing imageMissing resource
  • 44. Fixing the web.config <staticContent> <mimeMapfileExtension=".svg" mimeType="image/svg+xml" /> </staticContent> http://colinmackay.scot/2014/11/23/deploying-a-node-js-with-express-application- on-azure/
  • 46. Follow up information•Blog: http://colinmackay.scot/ –Slide deck available soon•Twitter: @colinmackay
  • 47. Introduction to Node.JSQuestion Timehttp://colinmackay.scot/tag/node-js/
  • 48. Follow up information•Blog: http://colinmackay.scot/ –Slide deck available soon•Twitter: @colinmackay