Node.js Introduction

Cat Chen

10 years ago...

How did you set up a web site 10 years ago?

  • Perl? ASP? PHP?
  • Windows server? Linux server?
  • VBScript? JScript

10 years ago...

I was working on:

  • DVBBS
  • Windows Server 2000
  • VBScript + JScript

10 years ago...

I needed to know:

  • ASP (VBScript)
  • Windows Server 2000 + IIS
  • VBScript + JScript

Now?

Just JavaScript

Indeed...

I need to know:

  • Client-Side JavaScript
  • Server-Side JavaScript (Node.js)

Let's start!

Hello World

				var http = require('http');
				var server = http.createServer(function(request, response) {
				    response.send('Hello, world!');
				});
				var port = 3000;
				server.listen(port);
			

Real World Cases!

Biz-to-Me Demo

What we learn...

  • No configuration for Apache or alike
  • No URL routing? You will see.

Trace-URL Demo

There is URL routing!

It's just like Rails or other MVC framework. It supports:

  • String definition
  • RegExp definition

What Express.js can do

  • Routing
  • Middleware
    • Logger
    • Body Parser
    • Method Override
    • Cookie Paser
    • Session
  • Templating Engine
  • Static Content

Packages?

NPM

Build your own packages!

  1. Use module.exports to write modules
  2. Provide package.json and index.js
  3. npm publish (use npm adduser for the first time)

Time to Deploy!

Your Server? No!

VPS? No!

Use Cloud!

Use cloud services like:

Deploy to Heroku

  1. gem install heroku (for the first time)
  2. heroku create --stack cedar to create an app
  3. Put web: node web.js in a file named Procfile
  4. Make sure that package.json is correct
  5. git push heroku
  6. heroku ps:scale web=1 to set web process number to 1

Please read this guide for more details.

What does Node.js mean to us?

Replacement of Apache, Lighttpd, etc?

Replacement of ASP, PHP, Rails, etc?

Node.js is for...

High Concurrency

Asynchronous IO

These enables...

  • More users
  • Better user experience
    • Real-time

Cool Stuff~

Check this out!

"One more thing"

JavaScript as a Daily Scripting Language

No more Python, Ruby, Bash, Make, etc. Just JavaScript.

http://catchen.me