node.js模板引擎
art-templateejsjade
为了让路由直接跳到显示页面(render)
并且可以在里面使用for循环 (这样可以直接渲染到页面 不用再ajax请求了)
这里的reander就是利用了art-template
![]ZSAWGJIBQNQGJSGAZVJ35.png
配置
config index.js

![]ZSAWGJIBQNQGJSGAZVJ35.png
const { MongoClient } = require('mongodb')const url = 'mongodb://121.36.222.9:12021' //自己的主机地址 +容器设置的端口const client = new MongoClient(url)const dbName = 'Student';async function main(table) {await client.connect();console.log('Connected successfully to server');const db = client.db(dbName);const collection = db.collection(table);return collection;}module.exports = main;
routers index.js
![]ZSAWGJIBQNQGJSGAZVJ35.png
const koa = require("koa")
const app = new koa()
const initProject = require("./config")
initProject(app)
app.listen(8000)
html
login
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"/>
</head>
<body>
<div class="container">
<form action="/doLogin" method="POST" role="form">
<legend>登录/注册页面</legend>
<div class="form-group">
<label for="">用户名</label>
<input type="text" class="form-control" name="username" placeholder="请输入用户名">
</div>
<div class="form-group">
<label for="">密码</label>
<input type="password" class="form-control" name="pwd" placeholder="请输入密码">
</div>
<button type="submit" class="btn btn-success">登录</button>
<a href="/register" class="btn btn-warning">快速注册</a>
</form>
</div>
</body>
</html>
Register
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"/>
</head>
<body>
<div class="container">
<form action="/doRegister" method="POST" role="form">
<legend>注册页面</legend>
<div class="form-group">
<label for="">用户名</label>
<input type="text" class="form-control" name="username" placeholder="请输入用户名">
</div>
<div class="form-group">
<label for="">密码</label>
<input type="password" class="form-control" name="pwd" placeholder="请输入密码">
</div>
<button type="submit" class="btn btn-danger">注册</button>
</form>
</div>
</body>
</html>
