Node.js LinkedIn Yahoo! Netflix JavaScript JavaScript Node.js Node.js JavaScript JavaScript Node.js Ruby C++ Java PHP JavaScript Node.js Node PHP Apache Node.js Node.js API JavaScript 前言 ix
Java C++ Ruby PHP JavaScript JavaScript ECMAScript JavaScript Node API C++ Java C++ Node big-endian API Node https://nodejs.org/en/ Node Node Mongo-Express-Angular-Node MEAN Node Node 文件 Node Node.js " "Node.js " " /docs LTS Node.js Stable Node API diff Node Current Node.js 6.0.0 Stable Node.js 6.0.x LTS Node.js API Node.js x 前言
Node.js 就是 Node Node.js "Node" Node 學習手冊 Node Node npm Node 1 Node Node Node C/C++ Node Node 1.0 4.0 2 Node Node Node buffer Node 3 Node npm Node Node Node Node Async Commander Underscore Node REPL 4 REPL 5 Node Node Apache proxy Node 前言 xi
Node Windows Unix OS X Linux 6 Node Node 7 Node TCP UDP HTTPS Secure Sockets Layer SSL Transport Layer Security TLS Node Node 子行程 Node ImageMagick 8 JavaScript Node.js/io.js ES6 ECMAScript 2015 ECMAScript 9 Node JavaScript Bluebird 10 全端 Node 開發 Express Node MongoDB Redis Node " " AngularJs Backbone.js Node 11 Node Node 12 Node / V8 Node xii 前言
第一章 Node Node Node Node PC Node Linux Windows 10 PC Raspberry Pi Node Android Node Arduino Uno IFTTT Marker Channel PC Node JavaScript ImageMagick Node PC Apache Node Node Node IFTTT IFTTT if-then Maker Channel https://ifttt.com/maker 1
Node Node Node.js Downloads https://nodejs.org/en/download/ Windows OS X SunOS Liunx ARM Windows Node Ubuntu Node Node "Node LTS " Node Ubuntu Node apt-get install make g++ libssl-dev git Node Windows Node Node Command Node Windows UI Arduino Uno Node Node Johnny-Five http://johnny-five.io/ Windows Windows Node Node PATH node Raspberry Pi Node ARM Raspberry Pi ARMv6 Raspberry Pi 2 ARMv7 /usr/ local wget https://nodejs.org/dist/v4.0.0/node-v4.0.0-linux-armv7l.tar.gz tar -xvf node-v4.0.0-linux-armv7l.tar.gz cd node-v4.0.0-linux-armv7l sudo cp -R * /usr/local/ 2 第一章 :Node 環境
Node Node Arduino Raspberry Pi Node 12 Node Node Hello World Node "Hello, World" "Hello, World" Node Node.js Hello World Node "Hello, World" JavaScript Windows Notepad++ Linux Vim var http = require('http'); http.createserver(function (request, response) { response.writehead(200, {'Content-Type': 'text/plain'}); response.end('hello World\n'); }).listen(8124); console.log('server running at http://127.0.0.1:8124/'); hello.js OS X Linux terminal Windows Node Command node hello.js 以 Node 說 Hello World 3
console.log() Server running at http://127.0.0.1:8124/ http://localhost:8124/ http://127.0.0.1:8124 Node "Hello World" 1-1 1-1 Node Windows 1-2 Windows Firewall Public Network Private Allow 1-2 Node 4 第一章 :Node 環境
Windows terminal/command Ctrl-C terminal terminal Node 5 Node Node 11 Node Hello World JavaScript "Hello World" Node HTTP HTTP Node var http = require('http'); Node http HTTP Node 3 Node 5 HTTP require http.createserver() Node callback 1-1 1-1 Hello World callback http.createserver(function (request, response) { response.writehead(200, {'Content-Type': 'text/plain'}); response.end('hello World\n'); }).listen(8124); 以 Node 說 Hello World 5
JavaScript Node 事件迴圈 callback 1-1 callback console.log() console.log('server running at http://127.0.0.1:8124/'); callback 2 Node callback callback header 200 Hello World Node Node Hello World Hello World Node 1-2 query string name=burningbird query query string 'world' 6 第一章 :Node 環境
1-2 Hello World var http = require('http'); var fs = require('fs'); http.createserver(function (req, res) { var name = require('url').parse(req.url, true).query.name; if (name === undefined) name = 'world'; if (name == 'burningbird') { var file = 'phoenix5a.png'; fs.stat(file, function (err, stat) { if (err) { console.error(err); res.writehead(200, {'Content-Type': 'text/plain'}); res.end("sorry, Burningbird isn't around right now \n"); } else { var img = fs.readfilesync(file); res.contenttype = 'image/png'; res.contentlength = stat.size; res.end(img, 'binary'); } }); } else { res.writehead(200, {'Content-Type': 'text/plain'}); res.end('hello ' + name + '\n'); } }).listen(8124); console.log('server running at port 8124/');?name=burningbird query string 1-3 以 Node 說 Hello World 7
1-3 Hello Burningbird Hello World fs File System var name = require('url').parse(req.url, true).query.name; URL URL res req name undefined world name burningbird 8 第一章 :Node 環境
burningbird fs.stat() header console.error() { [Error: ENOENT: no such file or directory, stat 'phoenix5a.png'] errno: -2, code: 'ENOENT', syscall: 'stat', path: 'phoenix5a.png' } header fs.stats() Node callback errback Node readfilesync() readfile() Node File System Node 1-3 fs.readfile(file, function(err,data) { res.contenttype = 'image/png'; res.contentlength = stat.size; res.end(data, 'binary'); }); I/O Node callback 2 try...catch callback Node I/O 以 Node 說 Hello World 9
Filesystem URL I/O 5 URL 6 File System File System 2 Node Node help -h --help $ node --help Node Usage: node [options] [ -e script script.js ] [arguments] node debug script.js [arguments] Node $ node -v or --version Node -c $ node -c or --check script.js V8 $ node --v8-options --harmony Harmony JavaScript LTS Current ES6 Node -p --print Node 2 process.env $ node -p "process.env" 10 第一章 :Node 環境
Node Node Windows OS X Linux Node virtual private network VPN Node Node VPS Node Node WordPress Node 必要的 root admin Node virtual private server VPS Node Linode VPN VPS root VPS VPS Apache Nginx https://www.nginx.com/ VPS Node 雲端 Node Node PC Node Node Node 運行環境 11
Node FTP Git 與 GitHub:Node 開發需求 Git Node Git Git Git https://git-scm.com/ GitHub https://try.github.io/levels/1/challenges/1 Git Git GitHub Node.js GitHub Node GitHub GitHub https://github.com/ Node GitHub https://help.github.com/categories/bootcamp/ Git GitHub Git https://git-scm.com/book/en/v2 Loeliger McCullough Version Control with Git O'Reilly, Bell Beer Introducing GitHub O'Reilly Node Node Node Git Microsoft Azure Git Google Cloud Platform GitHub https://github.com/nodejs/ node-v0.x-archive/wiki/node-hosting Node 12 第一章 :Node 環境
Node LTS 2014 Node io.js Node io.js Joyent Node Node Joyent V8 Node.js Node Linux Fundation Node Foundation Node 4.0 Node 1.0 Node 1.0 io.js 3.0 Node Linux Semver http://semver.org/ Node Semver Node.js 4.3.2 4 3 2 Windows Stable 5.7.1 Linux Current 6.0.0 Node Foundation LTS Long- Term Support Node.js v4 2018 4 Node Foundation 2015 10 Stable Node.js v5 Node 5.x.x 2016 4 Node.js v6 Stable Current LTS Node v4 6.0.0 Current 2016 4 Node 6.0.0 5.x 2016 10 LTS Node Stable Current Node 的 LTS 與升級 13
2018 4 Node v4 semvermajor bumps Node.js v4 v4 v5/v6 LTS / semver-major bump LTS Node.js v4 V8 Current 11 Node Node Node node -v Node Windows sudo sudo apt-get update sudo apt-get upgrade --show-upgraded Node 14 第一章 :Node 環境
npm Node sudo npm cache clean -f sudo npm install -g sudo n stable Windows OS X Raspberry Pi Node Node.js Node Version Manager Linux OS X Node Version Manager nvm https://github.com/creationix/nvm Node Node package manager npm https://www.npmjs.com/ Node sudo npm install npm -g n npm -v Node npm npm 3 npm Node sudo npm update -g Node V8 ES6 Node JavaScript V8 Google Chrome 2008 V8 JavaScript just-in-time JIT JavaScript JavaScript JavaScript V8 C++ Node V8 與 ES6 15
Microsoft Node.js Microsoft Node Chakra JavaScript 12 Node v4.0 V8 4.5 Chrome Node V8 Node ECMA-262 ECMAScript 2015 ES6 Node v6 V8 Node v6 V8 5.0 Node V8 Node ES6 harmony --harmony node --harmony app.js ES6 Node.js V8 穩定版 Node.js 不 V8 穩定版 --es_staging --harmony 開發中 harmony --harmony_destructuring 9 Node ES6 Node ES6 Classes Promises Symbols Arrow Generators 16 第一章 :Node 環境
Collections let spread operator Node C/C++ Node Node JavaScript Node C++ C C++ C/C++ 附加元件 Node Node C/C++ V8 Node Node Hello World C/C++ node-gyp.node binding.gyp JSON { "targets": [ { "target_name": "addon", "sources": [ "hello.cc" ] } ] } Node node-gyp configure Unix Makefile Windows vcxproj build/ Node node-gyp build 進階 :Node 的 C/C++ 附加元件 17
build/release Node 3 Microsoft Azure https://azure.microsoft.com/en-us/documentation/articles/ nodejs-use-node-modules-azure-apps/ node-serialport http://www.voodootikigod.com/onmaintaining-a-native-node-module/ C/C++ JavaScript 3 Node v0.8 v6.x Native Abstractions for Node.js NAN https://github.com/nodejs/nan Node.js 18 第一章 :Node 環境