javascript - NodeJS , gulp , Error: listen EADDRINUSE :::3000 - Stack Overflow

i am working with NodeJS and i am using gulp.My foler look like that : Root distnode_modulessrcindex.ht

i am working with NodeJS and i am using gulp.

My foler look like that :

Root 
  dist
  node_modules
  src
    index.html
  gulpfile.js
  package.json

My gulpfile is :

"use strict";

var gulp = require('gulp');
var connect = require('gulp-connect'); // runs a local dev server 
var open = require('gulp-open'); // open a URL in a web browser

var config ={
    port : 3000,
    devBaseUrl : 'http://localhost',
    paths:{
        html:'./src/*.html',
        dist:'./dist'
    }
}

//Start a local development server 
gulp.task = ('connect' , function(){
    connect.server({
        root:['dist'],
        port: config.port,
        base: config.devBaseUrl,
    }); 
});

gulp.task('open', ['connect'], function(){
    gulp.src('dist/index.html').pipe(open({uri: config.devBaseUrl + ":" + config.port + '/'}))
});

gulp.task('html',function(){
    gulp.src(config.paths.html)
        .pipe(gulp.dest(config.paths.dist))
        .pipe(connect.reload());
});

gulp.task('default', ['html', 'open']);

When i am type 'gulp' in the cmd i get this error :

C:\Users\maor\Documents\NodeProject\2>gulp
[13:18:28] Using gulpfile ~\Documents\NodeProject\2\gulpfile.js
[13:18:28] Server started http://localhost:3000
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::3000
    at Object.exports._errnoException (util.js:1018:11)
    at exports._exceptionWithHostPort (util.js:1041:20)
    at Server._listen2 (net.js:1262:14)
    at listen (net.js:1298:10)
    at Server.listen (net.js:1394:5)
    at ConnectApp.server (C:\Users\maor\Documents\NodeProject\2\node_modules\gulp-connect\index.js:57:19)
    at new ConnectApp (C:\Users\maor\Documents\NodeProject\2\node_modules\gulp-connect\index.js:37:10)
    at Object.server (C:\Users\maor\Documents\NodeProject\2\node_modules\gulp-connect\index.js:170:12)
    at Gulp.gulp.task (C:\Users\maor\Documents\NodeProject\2\gulpfile.js:18:10)
    at Object.<anonymous> (C:\Users\maor\Documents\NodeProject\2\gulpfile.js:29:6)

I really dont know what the problem is , i already checked and the port : 3000 is free. can you guys help me figure what the problem is ?

i am working with NodeJS and i am using gulp.

My foler look like that :

Root 
  dist
  node_modules
  src
    index.html
  gulpfile.js
  package.json

My gulpfile is :

"use strict";

var gulp = require('gulp');
var connect = require('gulp-connect'); // runs a local dev server 
var open = require('gulp-open'); // open a URL in a web browser

var config ={
    port : 3000,
    devBaseUrl : 'http://localhost',
    paths:{
        html:'./src/*.html',
        dist:'./dist'
    }
}

//Start a local development server 
gulp.task = ('connect' , function(){
    connect.server({
        root:['dist'],
        port: config.port,
        base: config.devBaseUrl,
    }); 
});

gulp.task('open', ['connect'], function(){
    gulp.src('dist/index.html').pipe(open({uri: config.devBaseUrl + ":" + config.port + '/'}))
});

gulp.task('html',function(){
    gulp.src(config.paths.html)
        .pipe(gulp.dest(config.paths.dist))
        .pipe(connect.reload());
});

gulp.task('default', ['html', 'open']);

When i am type 'gulp' in the cmd i get this error :

C:\Users\maor\Documents\NodeProject\2>gulp
[13:18:28] Using gulpfile ~\Documents\NodeProject\2\gulpfile.js
[13:18:28] Server started http://localhost:3000
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::3000
    at Object.exports._errnoException (util.js:1018:11)
    at exports._exceptionWithHostPort (util.js:1041:20)
    at Server._listen2 (net.js:1262:14)
    at listen (net.js:1298:10)
    at Server.listen (net.js:1394:5)
    at ConnectApp.server (C:\Users\maor\Documents\NodeProject\2\node_modules\gulp-connect\index.js:57:19)
    at new ConnectApp (C:\Users\maor\Documents\NodeProject\2\node_modules\gulp-connect\index.js:37:10)
    at Object.server (C:\Users\maor\Documents\NodeProject\2\node_modules\gulp-connect\index.js:170:12)
    at Gulp.gulp.task (C:\Users\maor\Documents\NodeProject\2\gulpfile.js:18:10)
    at Object.<anonymous> (C:\Users\maor\Documents\NodeProject\2\gulpfile.js:29:6)

I really dont know what the problem is , i already checked and the port : 3000 is free. can you guys help me figure what the problem is ?

Share Improve this question asked Mar 22, 2017 at 12:03 TalTal 2355 silver badges14 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

Are you running any other applications that might be using port 3000?

It's possible that a previous instance of node may still be running, even if you intended to kill it. Check your processes, I sometimes get this issue and generally use

killall node

to resolve it.

This problem arise, when node process already running on the port.

You can fix it by

pkill node

OR you can use this

killall node

you still see node process with this mand: ps aux | grep node.

If you are using windows, then open task manager & in process tab, search node & right click on that process & end process.

Surely it will work.

Or better still you can change the port number to something else like 8000.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1740244768a4214987.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信