server.js 820 B

12345678910111213141516171819202122232425262728
  1. const express = require('express');
  2. const http = require('http');
  3. const index = require('./routes/index.js');
  4. const livereload = require('livereload');
  5. const connectLivereload = require('connect-livereload')
  6. const path = require("path");
  7. const port = 3001;
  8. const viewsSrc = path.join(__dirname, 'views');
  9. const appLiveReload = livereload.createServer();
  10. appLiveReload.watch(viewsSrc)
  11. appLiveReload.server.once("connection", () => {
  12. setTimeout(() => {
  13. appLiveReload.refresh('/');
  14. }, 100);
  15. })
  16. const app = express();
  17. app.use(connectLivereload());
  18. app.use(express.static(path.join(__dirname, 'public')));
  19. app.set('views', viewsSrc);
  20. app.set('view engine', 'pug');
  21. app.get('/', index.index);
  22. http.createServer(app).listen(port, function(){
  23. console.log('Express server listening on port ' + port);
  24. });