Skip to content

Instantly share code, notes, and snippets.

@pramodmg
Created July 28, 2017 06:44
Show Gist options
  • Save pramodmg/6d9cad3289423741c7ab5ffb357532f3 to your computer and use it in GitHub Desktop.
Save pramodmg/6d9cad3289423741c7ab5ffb357532f3 to your computer and use it in GitHub Desktop.
A simple Gulp + browser-sync + express
'use strict';
// simple express server
var express = require('express');
var app = express();
var router = express.Router();
var port = 5001;
app.use(express.static('public'));
app.get('/', function (req, res) {
res.sendfile('./public/index.html');
// res.send('Hello world'); // to check the data is being passed to the UI
});
app.listen(port, function () {
console.log('the port that it is listening to us ', port);
});
'use strict';
var gulp = require('gulp');
var browserSync = require('browser-sync');
var nodemon = require('gulp-nodemon');
gulp.task('default', ['browser-sync']);
gulp.task('browser-sync', ['nodemon'], function () {
browserSync.init(null, {
proxy: "http://localhost:5001",
files: ["public/**/*.*"],
browser: "google chrome",
port: 7008,
});
});
gulp.task('nodemon', function (cb) {
var start = false;
return nodemon({
script: 'app.js'
}).on('start', function () {
if (!started) {
cb();
start = true;
}
});
});
/* please keep this file in the public directory */
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<p> A simple HTML PAGE </p>
</body>
</html>
{
"name": "Simple-Try",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.18.13",
"gulp": "^3.9.1",
"gulp-nodemon": "^2.2.1"
},
"dependencies": {
"express": "^4.15.3"
}
}
body {
background: #e1e1e1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment