文章推荐
Express-官方文档
Express-菜鸟教程
阮一峰博客-Express
案例代码github
// app.js
var express = require('express');
var app = express();
app.get('/',function(req,res){
res.sendFile(__dirname + '/views/index.html')
})
app.get('/about',function(req,res){
res.sendFile(__dirname + '/views/about.html')
})
app.get('/article',function(req,res){
res.sendFile(__dirname + '/views/article.html')
})
app.listen(3000)
<!-- index.html -->
<html>
<head>
<title>静态网页模板</title>
</head>
<body>
<h1>首页</h1>
<footer>
<p>
<a href="/about">自我介绍</a> - <a href="/article">文章</a>
</p>
</footer>
</body>
</html>
<!-- about.html -->
<html>
<head>
<title>静态网页模板</title>
</head>
<body>
<h1>自我介绍</h1>
<footer>
<p>
<a href="/">首页</a> - <a href="/article">文章</a>
</p>
</footer>
</body>
</html>
<!-- article.html -->
<html>
<head>
<title>静态网页模板</title>
</head>
<body>
<h1>文章</h1>
<footer>
<p>
<a href="/">首页</a> - <a href="/about">自我介绍</a>
</p>
</footer>
</body>
</html>
node app.js // 启动