An Introduction to NodeJS



An Introduction to NodeJS

1 1


nodejs-presentation

An introduction to NodeJS

On Github cjus / nodejs-presentation

An Introduction to NodeJS

Presented by Carlos Justiniano / HC.JS / @cjus / ver: 1.0.0

About me

  • Carlos Justiniano, HC.JS founder and a long-time programmer
  • A fullstack developer using NodeJS since 2011
  • Developed Node applications in production use
  • Developer at MediaMath, note: we're hiring!

Node = NodeJS

So, what is Node?

  • "Node.js is an open source, cross-platform runtime environment for server-side and networking applications". - Wikipedia
  • A platform for building applications, using JavaScript, for use on and off the net
  • An application optimized for performing high speed input/output operations

Node's early beginnings

  • Node was created in 2009 by Ryan Dahl which he first published for under Linux
  • Ryan debuted Node at the November 2009 European JSConf where it received a standing ovation
  • Node's continued development was sponsored by Joyent the company where Ryan worked

Node's popularity

  • https://goo.gl/1CPmlS

Who uses Node?

Backed by the Node.js Foundation Supported by Google, Microsoft and IBM Supported by a legion of open source developers And it's used by a few companies you may have heard of ☞
  • Google
  • Microsoft
  • IBM
  • SAP
  • StrongLoop
  • Netflix
  • Walmart
  • Target
 
  • LinkedIn
  • Mozilla
  • PayPay
  • New York Times
  • Fidelity Investments
  • Uber

And many many more: https://goo.gl/XvVEoV

Getting started with Node

  • Download and Install Node for your machine at: https://nodejs.org/
  • Click on the big green Install button

Confirming Node is installed

      $ node --version
      v0.12.7
    

Sample Code!

All of the sample code in this presentation is available on the GitHub repo's subfolder:

  • https://github.com/cjus/nodejs-presentation/tree/master/NodeJSProjects

Sample Code: A really simple Node app

Demos:

  • Node as a JavaScript execution engine
  • A node script can be a one line program
  • Super easy to get started using Node
      console.log('Hello future Node developers!');
    

Sample Code: OSInfo

Demos:

  • How to write a Node commandline program that accepts arguments
  • Calls to the Node process object for querying operating system and environment variables
  • Available here: https://github.com/cjus/nodejs-presentation/tree/master/NodeJSProjects/commandline

Sample Code: WordCount

Demos:

  • Yet another commandline program
  • How to read and process text files using Node
  • How to use and write external Node modules
  • Available here: https://github.com/cjus/nodejs-presentation/tree/master/NodeJSProjects/commandline

Sample Code: hello using Node

  • Demos a simple Node application which responds to a web request with a text message
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

Introducing Express

  • You can build incredibly powerful networking applications using Node and built-in networking features
  • However, as a backend web developer you don't want to write your own version of Apache or Nginx
  • Enter web frameworks, such as Express.JS

Building web applications using Node

  • Express.JS is a Fast, unopinionated, minimalist web framework for Node.js
  • Express is a framework that handles much of the functionality found in web servers
  • Available at: http://expressjs.com/

Installing Express

  • Because Express is a framework that sits on top of Node, you'll need to make sure you have Node installed.
  • Simple instructions here: http://expressjs.com/starter/installing.html
  $ mkdir myapp
  $ cd myapp
  $ npm init
  $ npm install express --save

Sample Code: hello using Express.JS

Demos:

  • A simple Node/Express application which responses to a web request with a text message
  • Available here: https://github.com/cjus/nodejs-presentation/tree/master/NodeJSProjects/web/simple
var express = require('express')
var app = express();

app.get('/', function(req, res) {
  res.send('Hello World');
});

app.listen(3000);
    

Installing Express Generator

  • Express Generator is a Node based commandline program which can generate the basic skeleton of a non-trivial web application
  • This saves you from building boilerplate code common to most web server applications you'll build
  • Simple instructions here: http://expressjs.com/starter/generator.html
$ mkdir myapp
$ cd myapp
$ npm init
$ npm install express-generator -g

Then you can use express-generator:

$ express myapp

Sample Code: Login

Demos:

  • How to build a Node and Express web application
  • How to serve web pages and handle RESTFul API calls
  • Available here: https://github.com/cjus/nodejs-presentation/tree/master/NodeJSProjects/web

What's next?

  • Visit the links in this slide and try the sample apps

The next Node talk will feature:

  • Building more advanced Node applications
  • A look at NPM - the Node Package Manager
  • Building your own Node modules
  • Publishing NPM packages
  • Extending Node, using C++
  • Building a RESTful API server using Node
  • Node and Microservices

Contact

  • cjus on Twitter and Github
  • Email: cjus34@gmail.com
  • About: http://cjus.me