學習nodejs之restful

var express = require('express'); //加載模塊
app = express(); //實例化express

app.get('/devices',function(req,res){
    res.writeHead(200,{'Content-Type':'text/plain'});
    res.end('devices');
})

app.get('/devices/:id',function(req,res){
    res.writeHead(200,{'Content-Type':'text/plain'});
    res.end('devices'+req.param('id'));
})

app.listen(8000); //監聽8000端口

console.log('httpd start @8000')


階段性理解,restful只是一種url風格shell

擴展,安裝expressexpress

npm config set registry  http://registry.cnpmjs.org  //切換源
npm install express  //安裝express
相關文章
相關標籤/搜索