Gulp-connect shows an error 'listen EADDRINUSE' 8080

非 Y 不嫁゛ 提交于 2019-12-12 18:32:45

问题


I have a simple gulpfile.js:I have a simple gulpfile.js:I have a simple gulpfile.js:I have a simple gulpfile.js:I have a simple gulpfile.js:I have a simple gulpfile.js:I have a simple gulpfile.js:I have a simple gulpfile.js

   var gulp = require('gulp');
var less = require('gulp-less');
var nodemon = require('gulp-nodemon');
var watch = require('gulp-watch-less');
var path = require('path');
var bower = require('gulp-bower');
var livereload = require('gulp-livereload');
var  connect = require('gulp-connect');

gulp.task('connect', function() {
  connect.server({
    root: ['./'],
    port:8080,
    livereload: true
  });
});


gulp.task('less', function() {
    // Code for the default task
    return gulp.src('less/style.less')
    .pipe(less())
    .pipe(gulp.dest('stylesheets'))

});

gulp.task('watch',function(){

    gulp.watch('less/**/*.less',['less']);

});


gulp.task('start', function () {
  nodemon({
    script: 'server.js'
  , ext: 'js html'
  , env: { 'NODE_ENV': 'development' }

  })
})


    gulp.task('default', ['start', 'watch','less','connect']);

server.js

var http=require('http');
var express=require('express');
var jade=require('jade');
var app=express();
var chalk = require('chalk');


 //var less = require('less');


//gestion des routes 

var server=http.createServer(app);
var port = process.env.PORT || 8080;
app.set('view engine','jade');
app.use("/stylesheets",express.static(__dirname + "/stylesheets"));
app.use("/lib",express.static(__dirname + "/lib"));
app.use("/script",express.static(__dirname + "/script"));
app.use("/less",express.static(__dirname + "/less"));
app.use("/bower_components",express.static(__dirname + "/bower_components"));

app.use("/img",express.static(__dirname+"/img"));
app.use("/font",express.static(__dirname+"/font"));
app.use("/lib",express.static(__dirname+"/lib"));


app.get('/',function(req,res){

    res.render('index');

});

when i run my application i get this error Any idea please ?:

**events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::8080
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at Server._listen2 (net.js:1236:14)
    at listen (net.js:1272:10)
    at Server.listen (net.js:1368:5)
    at Object.<anonymous> (C:\Users\achraf\Desktop\portfolio\server.js:52:8)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)**

console

λ gulp
[22:35:56] Using gulpfile ~\Desktop\portfolio\Gulpfile.js
[22:35:56] Starting 'start'...
[22:35:56] Finished 'start' after 5.68 ms
[22:35:56] Starting 'watch'...
[22:35:56] Finished 'watch' after 35 ms
[22:35:56] Starting 'less'...
[22:35:56] Starting 'connect'...
[22:35:56] Finished 'connect' after 23 ms
[22:35:57] Server started https://localhost:8080
[22:35:57] LiveReload started on port 35729
[22:35:57] [nodemon] 1.8.1
[22:35:57] [nodemon] to restart at any time, enter `rs`
[22:35:57] [nodemon] watching: *.*
[22:35:57] [nodemon] starting `node server.js`
[22:35:57] Finished 'less' after 402 ms
[22:35:57] Starting 'default'...
[22:35:57] Finished 'default' after 25 μs
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::8080
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at Server._listen2 (net.js:1236:14)
    at listen (net.js:1272:10)
    at Server.listen (net.js:1368:5)
    at Object.<anonymous> (C:\Users\achraf\Desktop\portfolio\server.js:52:8)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
 [22:35:59] [nodemon] app crashed - waiting for file changes before starting...

回答1:


Seems like the specified port (8080) is already in use by another process. Run the following command to check the running process:

netstat -tulpn | grep :8080

Or try a different port in your server.js

var port = process.env.PORT || 4000;



回答2:


I've got same issue with gulp-connect. You just need to change port in your gulpfile.js to another.

    gulp.task('connect', function() {
    connect.server({
        root: 'app',
        port: 8090,
        livereload: true
    });
});


来源:https://stackoverflow.com/questions/35977029/gulp-connect-shows-an-error-listen-eaddrinuse-8080

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!