LHUIOSC / @jhen
facebook group: http://facebook.com/groups/lhuiosc
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/');
直接來寫個基本的網頁
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<!doctype html>' +
'<html>' +
'<head><title>Hello World</title></head>' +
'<body>' +
'<h1>Hello World</h1>' +
'<p>This is a Node.js example.</p>' +
'</body>' +
'</html>');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
印出 url, method, useragent 資訊
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<!doctype html>' +
'<html>' +
'<head><title>Hello World</title></head>' +
'<body>' +
'<h1>Hello World</h1>' +
'<p>This is a Node.js example.</p>' +
'<p>request url: ' + req.url + '</p>' +
'<p>http method: ' + req.method + '</p>' +
'<p>useragent: ' + req.headers['user-agent'] + '</p>' +
'</body>' +
'</html>');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
var isMobile = {
Android: function() {
return /Android/i.test(req.headers['user-agent']);
},
BlackBerry: function() {
return /BlackBerry/i.test(req.headers['user-agent']);
},
iOS: function() {
return /iPhone|iPad|iPod/i.test(req.headers['user-agent']);
},
Windows: function() {
return /IEMobile/i.test(req.headers['user-agent']);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry()
|| isMobile.iOS() || isMobile.Windows());
}
};
var message = isMobile.any() ? 'is mobile' : 'not mobile';
var http = require('http');
var qs = require('querystring');
http.createServer(function (req, res) {
var method = req.method;
var content = '';
res.writeHead(200, {'Content-Type': 'text/html'});
if (method === 'GET') {
content = '<form action="/" method="POST">' +
'<input type="text" name="msg" />' +
'<button type="submit">Submit</button>' +
'</form>';
res.end(content);
}
else if (method === 'POST') {
var formData = '';
req.on('data', function(data) {
formData += data;
});
req.on('end', function() {
var querys = qs.parse(formData);
res.end('input ' + querys.msg);
});
}
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
var fs = require('fs');
fs.readFile('read-file.js', 'utf8', function(err, data) {
if (err) {
return console.log(err);
}
console.log(data);
});
var http = require('http');
var fs = require('fs');
var url = require('url');
http.createServer(function (req, res) {
var pathname = url.parse(req.url).pathname;
if (pathname === '/') {
pathname = '/index.html';
}
pathname = pathname.replace('/', '');
fs.readFile(pathname, 'utf8', function(err, data) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/html'});
res.end('Not Found\n');
return;
}
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(data);
});
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
我想同儕很多早期都會遇到這種問題
然後浪費很多時間在上面
$ git config --global user.name "Jhen"
$ git config --global user.email jhen@jhen.me
config (只需設定一次)
init project
$ git init project_name
// or
$ cd project_name && git init
複製一份 repo 到你的帳號
然後你的新 repo 會顯示 forked from xxx
要求上游合併你新增出來的 commit
用 LHUIOSC 社網來示範好了
git clone <url>