标签:
app.js
var express=require("express"); var app=express(); app.get(‘/readid/:id‘,function(req,res){ res.send(req.params.id); }); var server = app.listen(3000,function(){ console.log("请在浏览器访问:http://localhost:3000/"); });
node 一下app.js后,访问:http://localhost:3000/readid/修改参数

结合ejs模板引擎的使用:
app.js
var express=require("express"); var app=express(); //指定模板引擎 app.set("view engine",‘ejs‘); app.use(express.static(__dirname+"/views")); //id为request参数值 app.get(‘/request/:id‘,function(req,res){ var locals={name:‘tinyphp‘,‘id‘:req.params[‘id‘]}; res.render(‘home.ejs‘,locals); }); var server = app.listen(3000,function(){ console.log("请在浏览器访问:http://localhost:3000/"); });
home.ejs
<html>
<head>
<title>my ejs template</title>
</head>
<body>
<p>Hi <%= name %></p>
<p>id: <%= id %></p>
</body>
</html>
node 一下app.js后,访问:http://localhost:3000/request/修改参数
id值随url参数改变


标签:
原文地址:http://www.cnblogs.com/tinyphp/p/4927654.html