Mean stack app wont open on port 3000

Im running a mean stack application using angular 5. when i start the app using. nodemon server it gives this information

[nodemon] 1.14.12
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `ng serve start server`
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2018-02-13T02:31:46.890Z
Hash: 272ecfdad82c3ea4d79b
Time: 7366ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 20 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 555 kB [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 33.9 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 7.41 MB [initial] [rendered]

from what i can see its starting the angular app and im trying to start express on port 3000

Here is my server.js file

var express = require("express");
var bodyParser = require('body-parser');
var path =  require('path');
var http = require('http');

var app = express();

var api = require('.server/api');

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

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

app.use("/", api);

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

};
var port = process.env.port || '3000'; 
app.set('port',port);

var server = http.createServer(app);

server.listen(port, function(){
    console.log("server running on 3k");
});

and here is my api.js file

var app = require('express');
var router = app.Router();
var mongocli = require('mongodb').MongoClient;
var objectid = require('mongodb').ObjectID;

const conn = function(closure){
    return mongocli.connect("mongodb://localhost:27017/newdb", (err, db)=>{
        if(err){
            return console.log(err);
        }
        closure(db);

    });
};

let response ={
    status:200,
    message: null,
    data:[]
};

var sendError = function(err, res){
    response.status = 501;
    response.message = typeof err == "object" ? err.message : err;
    res.status(501).json(response);


}

router.get("/tutoral", (req,res)=>{
    conn((db)=>{
        db.collection('mycol').find().toArray().then((mycol)=>{
            response.data = mycol ; 
            res.json(response);
        });

    });
});

module.exports = router;

i don't know if maybe my folder structure is to blame or just my code is a little of i would appreciate any help i can get with this issue

1 answer

  • answered 2018-02-13 02:39 sklingler93

    ** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

    It looks like the dev server is running on port 4200. Looking at the code that means you probably have an environment variable set