0

目前,我正在尝试使用 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 应用程序在没有 nodemon 的情况下运行良好,我只想在同一端口上运行 express 服务器,即 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)

github:https ://github.com/dimitri-a/grunt_yoyo.git

4

1 回答 1

1

该错误意味着端口 8080 已在使用中。尝试杀死您可能正在运行的任何其他服务器,或更改

app.listen(8080); 

到另一个港口

app.listen(8081);
于 2016-10-06T13:03:19.903 回答