标签:工具 cat pat name hand 操作 data ogg get
app.js
[html] view plain copy
//初始化包
var express = require(‘express‘);
var path = require(‘path‘);
var favicon = require(‘serve-favicon‘);
var logger = require(‘morgan‘);
var cookieParser = require(‘cookie-parser‘);
var bodyParser = require(‘body-parser‘);
var mysql = require("mysql");
var jade = require(‘jade‘);
var routes = require(‘./routes/index‘);
var app = express();
//加载引擎模板
app.set(‘view engine‘, ‘jade‘);
app.set(‘views‘, path.join(__dirname, ‘views‘));
//调用工具
app.use(logger(‘dev‘));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, ‘public‘)));
routes(app);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error(‘Not Found‘);
err.status = 404;
next(err);
});
// will print stacktrace
if (app.get(‘env‘) === ‘development‘) {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render(‘error‘, {
message: err.message,
error: err
});
});
}
// no stacktraces leaked to users
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render(‘error‘, {
message: err.message,
error: {}
});
});
app.listen(3000);
[html] view plain copy 在CODE上查看代码片派生到我的代码片
var user = require("../models/user.js");
module.exports = function (app) {
app.post(‘/updateUsers‘, function (req, res, next) {
user.updateUsers({
sql: "update user SET username=?,password=?,age=?,info=? WHERE id = ?",
params: [ req.body.username, req.body.password, req.body.age, req.body.info, req.body.id ]
}, function (data) {
res.send(data);
});
});
app.post(‘/deleteUsers‘, function (req, res, next) {
user.deleteUsers({
sql: "DELETE FROM user WHERE id = " + req.body.id
}, function (data) {
res.send(data);
});
});
app.post(‘/addUsers‘, function (req, res, next) {
user.addUsers({
data: {
username: req.body.username,
password: req.body.password,
age: req.body.age,
info: req.body.info
},
sql: "INSERT INTO user SET ?"
}, function (data) {
res.send(data);
});
});
};
标签:工具 cat pat name hand 操作 data ogg get
原文地址:http://www.cnblogs.com/flower46273736/p/6322517.html