});
app.get(‘/y’, function (req, res) {
res.send(‘叶小钗’);
});
app.get(‘/register’, function (req, res) {
res.render(‘register’, { title: ‘注册页面’ });
});
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel=’stylesheet’ href=’/stylesheets/style.css’ />
</head>
<body>
<h1><%= title %></h1>
<form method=”post”>
<div>用户名:<input type=”text” name=”name”/></div>
<div>密码:<input type=”password” name=”password”/></div>
<div><input type=”submit” value=”登陆”/></div>
</form>
</body>
</html>
这个样子,我们页面就形成了:

基本程序有了,我们现在需要数据库支持,于是我们要安装mongoDB环境
MongoDB
MongoDB是一个基于分布式文件存储的NoSQL的一种,由C++编写,MongoDB支持的数据结构松散,类似json,我们知道json可以支持任何类型,所以可以搞出很复杂的结构
{
id: 1,
name: ‘叶小钗’,
frinds: [
{ id: 2, name: ‘素还真’ },
{ id: 3, name: ‘一页书’ }
]}
安装MongoDB
首先去http://www.mongodb.org/downloads下载安装文件,然后将文件拷贝到D盘改名mongodb,然后在里面新建blog文件夹
然后打开命令行工具将目录切换至bin,输入:
mongod -dbpath d:mongodbblog
设置blog文件夹为工程目录并启动数据库,为了方便以后我们写一个命令以后直接点击就启动数据库了:
d:mongodbbinmongod.exe -dbpath d:mongodbblog
链接MongoDB
数据库安装成功后,我们的程序还需要相关的“驱动”程序才能链接数据库,这个时候当然要下载包……
打开package.json在dependencies新加一行
{
“name”: “application-name”,
“version”: “0.0.1”,
“private”: true,
“scripts”: {
“start”: “node app.js”









