第六章 請求與回應物件
URL的各部分
http://localhost:3000/about?test=1#history
https://google.com/#q=express
| 協定 | 主機名稱 | 連接埠 | 路徑 | 查詢字串 | 片段 |
| http:// https:// | localhost google.com | :3000 | /about / | ?test=1 | #history #q=express |
http://localhost:3000/about?test=1#history
https://google.com/#q=express
| 協定 | 主機名稱 | 連接埠 | 路徑 | 查詢字串 | 片段 |
| http:// https:// | localhost google.com | :3000 | /about / | ?test=1 | #history #q=express |
npm install --save express
var express = require('express');
var app = express();
app.set('port', process.env.PORT || 3000);
app.get('/', function(req, res) {
res.type('text/plain');
res.send('Bake Node Book');
});
app.get('/about', function(req, res) {
res.type('text/plain');
res.send('About my Bake Node Book');
});
app.use(function(req, res){
res.type('text/plain');
res.status(404);
res.send('404 - Not Found');
});
app.use(function(err, req, res, next){
console.error(err.stack);
res.type('test/plain');
res.status(500);
res.send('500 - Server Error');
});
app.listen(app.get('port'), function(){
console.log('Express started on http://localhost:');
app.get(('port') + ';press Ctrl-C to terminate.');
});
繼續閱讀 “使用Node+Express 建構網站(一)” 
嚴格模式(strict)和遺留模式(legacy)
//遺留模式繼續閱讀 “Node.js+Express+MongoDB+Vue.js(二)”
const assert = require('assert');
//嚴格模式
const assert = require('assert').strict;