北護樂學程式冬令營 2017
TRANSCRIPT
-
NODE.JS 2017
-
GoogleNode.js(3)http://www.books.com.tw/products/0010660634
http://www.nodebeginner.org/index-zh-tw.html#a-basic-http-server
-
NODE.JS
React.js
D3.js
React Native
Angular.js
framework~!
-
NODE.JS
Server side script
Node.js event-drivennon-blockingI/O LinkedInYahooeBay
-
CentOS 7 http://ftp.yzu.edu.tw/Linux/CentOS/7/isos/x86_64/CentOS-7-x86_64-DVD-1611.iso
Visual Studio Code, Sublime NodePad++
-
Virtual Box: https://www.virtualbox.org
Vmware Workstation (: http://www.vmware.com/products/player/playerpro-evaluation.html
Mac Parallels , : http://www.parallels.com
-
RAM 4G
CPU
CentOS 7.
-
NODE.JS
https://blog.gtwang.org/web-development/install-node-js-in-windows-mac-os-x-linux/
google node.js download
-
CENTOS
-
google centos-7 - OpenFoundry
Linux Linux >
-
Yum install xxxxxx
Port firewall-cmd permanent --add-port=2888/tcp
firewall-cmd --permanent --add-service=http
reload ~!firewall-cmd --reload
-
NODE.JS
-
NODE.JS
google chrome Javascript V8
V8 JavaScript
JavaScript
non-blocking)
=> npm !
-
NODE.JS
Netflix
Amazon
Paypal
Adobe
LinkedIn
Uber
Medium
eBaysource: monster.com & Quora
-
NODE.JS
Node.js?
web app, e.g. google excel
Server API, request
streaming application
CPU >
-
NODE.JS NPM
curl --silent --location https://rpm.nodesource.com/setup_7.x | bash -
yum install nodes
-
NPM
https://www.npmjs.com
-
NPM - GLOBAL INSTALL
$ npm install -g
#
$ npm install express -g
# express
$ express new app
-
NPM -
$ cd /path/to/the/project
$ npm install
#
$ npm install express
# `var express = require( 'express' );` express .
-
NPM -
$ npm uninstall -g
#
$ npm uninstall express -g
-
NPM -
$ cd /path/to/the/project
$ npm uninstall
#
$ npm uninstall express
packages.json
-
NPM -
$ npm search
#
$ npm search express
-
NPM -
.$ npm ls -g
.$ npm ls -gl
-
CLASS1- BLOCKING CODE
mkdir class1
cd class1
npm init
nano index.js
-
// synchrounous example
console.log('hello world');
var fs= require("fs");
var data = fs.readFileSync('content.txt');
console.log(data.toString()); console.log("End");
End : c++, C#, PHP, java
-
(NON-BLOCKING)
nano index2.js
// aynchrounous example
var fs = require("fs");
fs.readFile('content.txt', function(err, data) { if (err) return console.error(err);
console.log( data.toString() );
}); console.log("Game over");
-
Game over
I love node.js !
But I love to write app as well.
Output:
-
CALLBACK
Callback ?
callback
-
CALLBACK
var request = require('request');
function job1() { request('http://www.eztravel.com.tw', function( error, response, body) { console.log('job 1 done'); // console.log(body); }) }
function job2() { console.log('job 2 done'); }
job1(); job2();
2
-
function Callback
-node.js
-
PRACTICE TIME
Q1:
Q2: callback
fs.readFile callback
start reading a file
end of the file
-
const fs = require('fs') console.log('start reading a file...') fs.readFile('file.md', 'utf-8', function (err, content) { if (err) { console.log('error happened during reading the file') return console.log(err) } console.log(content) }) console.log('end of the file')