"Port 4200 is already in use. Use '--port' to specify a different port."

Discussão em 'Angular' iniciado por Dnl, Janeiro 3, 2025.

  1. Dnl

    Dnl Guest

    Hey i am runnning an angular2 app with express as backend. Getting the following issue:

    [3] Port 4200 is already in use. Use '--port' to specify a different port.
    [3] [nodemon] app crashed - waiting for file changes before starting...
    [1] [HPM] Error occurred while trying to proxy request /api/jobs from localhost:4200 to http://localhost:3000 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)


    server.js:

    import * as bodyParser from 'body-parser';
    import * as dotenv from 'dotenv';
    import * as express from 'express';
    import * as morgan from 'morgan';
    import * as mongoose from 'mongoose';
    import * as path from 'path';

    import setRoutes from './routes';

    const app = express();
    dotenv.load({path: '.env'});
    app.set('port', (process.env.PORT || 3000));

    app.use('/', express.static(path.join(__dirname, '../')));

    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({extended: false}));

    app.use(morgan('dev'));

    mongoose.connect(process.env.MONGODB_URI);
    const db = mongoose.connection;
    (<any>mongoose).Promise = global.Promise;

    db.on('error', console.error.bind(console, 'connection error:'));
    db.on('open', () => {
    console.log('Connected to MongoDB');
    setRoutes(app);

    app.get('/*', function (req, res) {
    res.sendFile(path.join(__dirname, '../index.html'));
    });

    app.listen(app.get('port'), () => {
    console.log('Angular 2 Full Stack listening on port ' +
    app.get('port'));
    });
    });

    export {app};


    edit: Here the hole code. I think i dont reach the line with db.on('open')

    when i inspect the port:

    [​IMG]

    I using concurrently: with this options

    "dev": "concurrently \"mongod\" \"ng serve -pc proxy.conf.json --open\" \"tsc -w -p server\" \"nodemon dist/server/server.js\"",

    Continue reading...

Compartilhe esta Página