我正试着用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']);
角度app在没有nodemon的情况下运行良好,我只想在同一个端口上运行快速服务器,即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)
答案 0 :(得分:1)
该错误表示端口8080已在使用中。尝试杀死您可能正在运行的任何其他服务器,或者更改
app.listen(8080);
到另一个端口
app.listen(8081);