使用 ng serve 时,Express 服务器不是 运行

Express server not running when using ng serve

当我从 angular-cli 使用 ng serve 命令时,我的 server.js 没有被执行。当我使用节点服务器时,它工作正常。

server.js:

const express = require('express')
const bodyParser = require('body-parser')
const path = require('path');
const http = require('http');
const api = require('./server/routes/api');

const port = 3000;

const app = express();

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

app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.get('/api', api);

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

const server = http.createServer(app);

server.listen(port, ()=>console.log(`Server is running on localhost:${port}`));

尝试使用以下命令:

  npm start

  node app.js