zoukankan      html  css  js  c++  java
  • node 基本搭建 server.js

    const express = require('express');
    const expressStatic = require('express-static');
    const bodyparser = require('body-parser');
    const multer = require('multer');
    const cookieParser = require('cookie-parser');
    const cookieSession = require('cookie-session');
    const consolidate = require('consolidate');
    const mysql = require('mysql');
    const expressRouter = require('express-route');
    const multerObj = multer({ dest: './static/upload' });
    const ejs = require('ejs')
    const server = express();
    server.listen(8080);
    const mysql = require('mysql');
    // 连接池
    var db = mysql.createPool({
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'learn'
    })
    // 1.请求数据
    // get 自带
    server.use(multerObj.any());
    server.use(bodyparser.urlencoded());
    // 2.cookie
    server.use(cookieParser());
    (function(){
    var keys = [];
    for (var i = 0; i < 10000; i++) {
    keys[i] = 'keys_' + Math.random()
    }
    server.use(cookieSession({
    name: 'sess_id',
    keys: keys,
    maxAge: 20 * 60 * 1000
    }))
    })()
    // 3.模版
    server.engine('html',consolidate.ejs);
    server.set('views','template');
    server.set('view engine','html');
    // 4.route
    server.use('/', require('./route/web/web.js')());
    server.use('/admin/', require('./route/admin/index.js')());
    // 5.default:static
    server.use(expressStatic('./static/'))
     
     
     
  • 相关阅读:
    使用opencv工程
    面试官最爱问的问题背后真相
    哎,哎,去了清华园
    突然发现兰皙欧洗面奶不错
    crs.exe 进程管理里面的流氓进程之封杀
    初步使用OpenCV
    动态网站基础
    Java IO -- 序列化的疑问
    建造模式
    MYSQL 从头开始-2(join)
  • 原文地址:https://www.cnblogs.com/dekui/p/8981888.html
Copyright © 2011-2022 走看看