Skip to content

Instantly share code, notes, and snippets.

@eioo
Last active January 25, 2018 14:47
Show Gist options
  • Save eioo/d9df057addfa9e520fb1d153f1c579cd to your computer and use it in GitHub Desktop.
Save eioo/d9df057addfa9e520fb1d153f1c579cd to your computer and use it in GitHub Desktop.
Gulp + Express + Nodemon + Browser-sync in harmony
const express = require('express');
const app = express();
const router = express.Router();
app.use(express.static('public'));
app.listen(3000);
const gulp = require('gulp');
const browserSync = require('browser-sync');
const nodemon = require('gulp-nodemon');
gulp.task('default', ['browser-sync'], () => {
});
gulp.task('browser-sync', ['nodemon'], () => {
browserSync.init(null, {
proxy: "http://localhost:3000",
files: ["public/**/*.*"],
port: 5000
});
});
gulp.task('nodemon', (callback) => {
let started = false;
return nodemon({
script: 'app.js'
}).on('start', () => {
if (!started) {
callback();
started = true;
}
});
});
<!-- This should be in './public' directory -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Page Title</title>
</head>
<body>
</body>
</html>
{
"name": "gulp-express-nodemon-browsersync",
"version": "0.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC",
"dependencies": {
"express": "^4.8.2"
},
"devDependencies": {
"browser-sync": "^1.3.3",
"gulp": "^3.8.7",
"gulp-nodemon": "^1.0.4"
}
}
@eioo
Copy link
Author

eioo commented Jan 16, 2018

Thanks @sogko. I modified it a bit to fit better for my needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment