Basic server with express templet folders routs and js och css included!
var express = require('express'); var mysql = require('mysql'); var http = require('http'); var bodyParser = require('body-parser'); var path = require('path'); var sess = require('express-session'); var val = require('express-validator'); var fs = require('fs'); var async = require("async"); var request = require("request"); var cheerio = require('cheerio'); var Promise = require('promise'); var childProcess = require('child_process') var con = mysql.createConnection({ host: 'localhost', user: '', password: '', database: '' }); con.connect(); var app = express(); app.set('view engine', 'ejs'); app.set('views', path.join(__dirname, 'app')); app.use('/js', express.static(__dirname + '/node_modules/bootstrap/dist/js')); app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended:true})); app.use(val()); app.use(express.static(path.join(__dirname, 'public'))); var sub; var uri; var id; var url; con.query('select * from pages where id = 1', function(err, res){ console.log(res + "err: " + err); sub = res[0].name; uri = res[0].uri; id = res[0].id; }); app.get('/', function(req, res){ res.render('index',{ title:sub, user: req.params.id, uri: uri}); }); app.get('/:uri', function(rq, rs){ rs.render('page',{ }); }); app.listen(3050, function(){ console.log('Server upp'); });