Overview of Nodejs What is Nodejs An opensource crossplatform JavaScript runtime environment that executes JavaScript code in a computing environment What is Nodejs capable of doing Generating dynamic page content ID: 788432
Download The PPT/PDF document "TechTalk: Node.js Jessica Davis, Juan He..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
TechTalk: Node.js
Jessica Davis, Juan Herrera, Ian Hoyt-McCullough, Varun Verma
Slide2Overview of Node.js
What is Node.js?
An open-source, cross-platform JavaScript run-time environment that executes JavaScript code in a computing environment
What is Node.js capable of doing?
Generating dynamic page content
Creating, opening, reading, writing,, deleting, and closing files on the server
Collecting form data
Adding, deleting, modifying data in your database
What operating systems officially support Node.js?
Linux, macOS, Microsoft Windows, and more
How is Node.js primarily used?
To build network programs, like web servers
Slide3History of Node.js
2009: Originally written by Ryan Dahl
Initial release supported on Linux and Mac OS X
Created after seeing a file upload progress bar on Flickr
Had to query the Web server for more information about the file
Node.js is a combination of:
Google’s V8 JavaScript engine
An event loop
A low-level I/O API
January 2010: npm was released as a package manager for Node.js
June 2011: Node.js was expanded to support more operating systems
Slide4Demo
A short demo…
npm init
npm scripts (npm start, npm test)
npm install <module> (nodemon)
Server code (next slide)
Dependencies (package.json)
Slide5Demo
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello world!');
}).listen(8000);
Slide6Pros
Javascript easy to learn for front-end developers
Compiles directly into machine code
Many resources and support available
High support for asynchronous events
Handles concurrent requests sequentially in a single thread, using less RAM and system resources
Slide7Cons
Cons
The single-threaded design can create bottlenecks when used in tasks with lots of computation
Must be careful dealing with exceptions in code, as uncaught ones may “bubble up” to the core node.js loop and crash the program for all requests
Coding paradigm is highly reliant on asynchronous callbacks, or functions run after certain functions return, so the scope and dependencies in the code can quickly become confusing, resulting in “callback hell” (need to learn to effective use of Promises in order to counteract this)
Slide8Alternatives/Competition
Ruby on Rails
Good for flexible databases
Worse performance than Node.js
Django
Highly Scalable
Monolithic, not fit for small apps
Flask
Minimalist, easy to learn
Not much Asynchronous support
Php
SQL integration is very simple, huge existing codebase
Not as powerful or flexible as Node.js
Slide9Use Cases
Good for streaming
Audio and Video files
Web apps similar to SoundCloud & Youtube
Specially suited for applications where you want to maintain persistent connection from the browser to server
Real-time updates
Online games
Collaborative tools
Chat interfaces
Gmail for instance
Cases of rapid development due to an extensive NPM ecosystem and ease of configuration
Cheaper cloud hosting
Desire a highly scalable application
Unified JavaScript development platform as it integrates well with MongoDB, AngularJS, & ReactJS
Slide10Use Cases
-Uber: Instantaneous real time updates, non-blocking
-Netflix: Handles the real time audio & video streaming efficiently
-LinkedIn: Efficiency & scale. Servers cut down from 15 to 4, & traffic capacity doubled
-NASA: Reduced access time by 300%. This is due to the persistent connection maintained by the server
Slide11Use Case Chat Example: Event Driven Apps
var
app =
require
(
'express'
)();
var
http =
require
(
'http'
).Server(app);
var
io =
require
(
'socket.io'
)(http);
app.get(
'/'
,
function
(
req, res
)
{
res.sendFile(__dirname +
'/index.html'
);
});
io.on(
'connection'
,
function
(
socket
)
{
console
.log(
'an user connected'
);
socket.on(
'disconnect'
,
function
()
{
console
.log(
'user disconnected'
);
});
});
http.listen(
3000
,
function
()
{
console
.log(
'listening on *:3000'
);
});
Slide12Use Case Chat Example: Event Driven Apps
Slide13Any Questions?
Slide14Sources/References
https://www.mindinventory.com/blog/pros-and-cons-of-node-js-web-app-development/
https://www.netguru.com/blog/pros-cons-use-node.js-backend
https://medium.com/the-node-js-collection/why-the-hell-would-you-use-node-js-4b053b94ab8e
https://www.w3schools.com/nodejs/nodejs_intro.asp
https://en.wikipedia.org/wiki/Node.js#Overview
https://medium.com/@TechMagic/nodejs-vs-ruby-on-rails-comparison-2017-which-is-the-best-for-web-development-9aae7a3f08bf
https://dzone.com/articles/nodejs-vs-djangois-javascript-better-than-python
https://www.codingdojo.com/blog/choosing-python-web-frameworks