現在、gulp で実行しようとして nodemon について頭を悩ませています。
var gulp = require('gulp'),
connect = require('gulp-connect');
var nodemon = require('gulp-nodemon');
gulp.task('connect', function() {
connect.server({
root: 'app',
livereload: true,
middleware: function(connect) {
return [connect().use('/bower_components', connect.static('bower_components'))];
}
});
});
gulp.task('html', function () {
gulp.src('./app/**/*.html')
.pipe(connect.reload());
});
gulp.task('js', function () {
gulp.src('./app/**/*.js')
.pipe(connect.reload());
});
gulp.task('watch', function () {
gulp.watch(['./app/**/*.html'], ['html']);
gulp.watch(['./app/**/*.js'], ['js']);
});
gulp.task('nodemon', function () {
nodemon({ script: 'quotes.js'
})
.on('restart', function () {
console.log('restarted!')
})
})
gulp.task('default', ['connect', 'watch','nodemon']);
angularアプリはノードモンなしで正常に動作します。同じポート、つまり8080でエクスプレスサーバーを実行したいだけです。
var express = require('express');
var app = express();
var quotes = [
{ author : 'Audrey Hepburn', text : "Nothing is impossible, the word itself says 'I'm possible'!"},
{ author : 'Walt Disney', text : "You may not realize it when it happens, but a kick in the teeth may be the best thing in the world for you"},
{ author : 'Unknown', text : "Even the greatest was once a beginner. Don't be afraid to take that first step."},
{ author : 'Neale Donald Walsch', text : "You are afraid to die, and you're afraid to live. What a way to exist."}
];
app.get('/quotes', function(req, res) {
res.json(quotes);
});
app.listen(8080);
console.log("The port is listening");
ただし、gulp を実行すると、次のエラーが発生します。
Error: listen EADDRINUSE :::8080
at Object.exports._errnoException (util.js:896:11)
at exports._exceptionWithHostPort (util.js:919:20)
at Server._listen2 (net.js:1246:14)
at listen (net.js:1282:10)
at Server.listen (net.js:1378:5)