平均堆栈应用程序不会在端口3000上打开

时间:2018-02-13 02:39:31

标签: node.js

我使用角度5运行一个平均堆栈应用程序。 当我使用启动应用程序时。 nodemon server它提供了此信息

[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]

从我可以看到它启动角度应用程序,我试图在端口3000上开始快递

这是我的server.js文件

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");
});

这是我的api.js文件

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;

我不知道我的文件夹结构是否应该受到责备,或者只是我的代码是一点点我会感谢我能解决这个问题的任何帮助

1 个答案:

答案 0 :(得分:1)

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

看起来dev服务器正在端口4200上运行。查看代码,这意味着你可能有一个环境变量集