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/'))
 
 
 

node 基本搭建 server.js的更多相关文章

  1. Node聊天程序实例06:server.js

    作者:vousiu 出处:http://www.cnblogs.com/vousiu 本实例参考自Mike Cantelon等人的<Node.js in Action>一书. server ...

  2. node+express 中安装nodemon实时更新server.js

    每次启动node server.js,有一个缺点,每次server.js文件有改动时,必须重新执行指令node server.js,新的代码才会起作用 解决方案1 全局安装 npm install s ...

  3. [转载]Sublime Text 3 搭建 React.js 开发环境

    [转载]Sublime Text 3 搭建 React.js 开发环境 Sublime有很强的自定义功能,插件库很庞大,针对新语言插件更新很快,配合使用可以快速搭建适配语言的开发环境. 1. babe ...

  4. node+express搭建个人网站(2)

    node+express搭建个人网站(1)这一节中成功启动了一个网站但还很简陋,仅仅打印了一个helloworld的网页 作为个人网站,我们当然想输出自己设计好的网页, 我们借助 Express 应用 ...

  5. swoole学习(二)----搭建server和client

    1.搭建server 1.1搭建server.php 1.搭建websocket服务器,首先建立 server.php 文件, <?php $server = new swoole_websoc ...

  6. vue-cli脚手架搭建Vue.js项目

    前提条件: 一.node.js 下载 https://nodejs.org/zh-cn/download/ 二.webpack 安装 npm install webpack -g   PS:-g 就是 ...

  7. node+express 搭建本地服务

    首先,得有node环境,其次建个项目 目录例如  酱紫! 再次 写server.js,当然你可以换个名字a.js .b.js.why.js随你喜欢 var express = require('exp ...

  8. 1.node接口搭建--express搭建服务器

    1.新建文件夹node 2.初始化 npm init 3.安装express npm install express 4.在入口文件(index.js)我的设置入口文件为(server.js)中写 / ...

  9. docker下node环境搭建

    初始化⼀个NodeJs程序 以下操作必须已经安装了NodeJS. ⾸先创建⼀个空⽂件夹.并创建以下⽂件: server.js package.json Dockerfile .dockerignore ...

随机推荐

  1. 使用LuceneUtil工具类,完成CURD操作

    package loaderman.curd; import java.util.ArrayList; import java.util.List; import loaderman.entity.A ...

  2. Python新利器之pipenv

    前言 之前学习异步asyncio库的时候,因为asyncio库支持Python3.5以上的版本,而我的Ubuntu14.04只有Python3.4,虽然下载了Python3.6,但是想直接利用ipyt ...

  3. mybatisplus

    1.selectById 根据主键查询一个对象,如果没有查到,则返回null: GxySchoolDto isExist = gxySchoolMapper.selectById(schoolEnti ...

  4. Linux Shell 自动备份脚本

    写一个使用shell脚本增量备份系统文件,顺便复习一下shell脚本相关的命令,这个脚本可以根据自己的需求来备份不同的文件或者文件夹,进行完整备份和增量备份. 参考的网址:http://blog.51 ...

  5. IIS 7 实现http跳转https 重定向方法

    官网的域名申请了一个SSL加密,导致原来的http无法访问了,网上找了一下解决方案,https://www.cnblogs.com/wer-ltm/p/10190535.html  按照这个方法进行了 ...

  6. c语言实行泛型hashmap

    代码出处:A simple string hashmap in C  https://github.com/petewarden/c_hashmap main.c (main2是官方源代码,main是 ...

  7. View的介绍和运用 && FlexBox布局

    开始我们今天的项目学习啦~~~~~~ 1> 第一步当然是创建项目啦: 进入终端: 创建ViewDemo项目 命令如下啦,你看懂了对吧...嘻嘻!!! 2>View的介绍和运用 项目安装创建 ...

  8. 增强for循环的简单总结

    整体来说:增强型for循环使用起来比较方便,代码也比较简单,如果只是操作集合中元素的而不使用索引的话,建议用此方法.对于普通for循环,如果需要使用索引进行其它操作的话,建议用这个. 详细来说:1,区 ...

  9. .Netcore 2.0 Ocelot Api网关教程(5)- 认证和授权

    本文介绍Ocelot中的认证和授权(通过IdentityServer4),本文只使用最简单的IdentityServer,不会对IdentityServer4进行过多讲解. 1.Identity Se ...

  10. Leetcode之动态规划(DP)专题-123. 买卖股票的最佳时机 III(Best Time to Buy and Sell Stock III)

    Leetcode之动态规划(DP)专题-123. 买卖股票的最佳时机 III(Best Time to Buy and Sell Stock III) 股票问题: 121. 买卖股票的最佳时机 122 ...