Node Basic Build Server.js

Source: Internet
Author: User

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 ');//connection pool var db = Mysql.createpool ({host: ' Local Host ', User: ' Root ', password: ' 123456 ', database: ' Learn '})//1. Request data//Get comes with Server.use (Multerobj.any ()); Server.use ( Bodyparser.urlencoded ());//2.cookieserver.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. Template server.engine (' HTML ', Consolidate.ejs); Server.set (' views ', ' TemplaTe '); Server.set (' View engine ', ' HTML ');//4.routeserver.use ('/', require ('./route/web/web.js ') ()); Server.use ('/ Admin/', require ('./route/admin/index.js ') ());//5.default:staticserver.use (Expressstatic ('./static/'))     

Node Basic build server.js

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.