You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何同时运行JSON Server与Angular 15应用?当前仅能单独启动其一

解决同时启动JSON Server与Angular 15应用的问题

要同时启动两个服务,你需要借助工具让多个命令并行执行,以下是具体方案:

方法1:使用concurrently(跨平台推荐)

这是最稳妥的跨平台方案,可在Windows、macOS、Linux上正常工作:

  1. 安装concurrently作为开发依赖:
npm install --save-dev concurrently
  1. 修改package.json的scripts部分,新增一个同时启动双服务的命令:
"name": "testapp",
"version": "0.0.0",
"scripts": {
  "ng": "ng",
  "start": "ng serve --port 4200",
  "build": "ng build",
  "watch": "ng build --watch --configuration development",
  "start-server": "npx json-server --watch test.json",
  "start:both": "concurrently \"npm run start\" \"npm run start-server\"",
  "test": "ng test"
}
  1. 执行以下命令即可同时启动Angular应用和JSON Server:
npm run start:both

方法2:原生命令(仅单平台适用)

若不想额外安装依赖,可根据操作系统使用原生命令,但跨平台兼容性差:

  • macOS/Linux:用&让其中一个命令后台运行
npm run start-server & npm run start
  • Windows(命令提示符):用start命令分开启动
start npm run start-server && npm run start
  • Windows(PowerShell):
Start-Process npm -ArgumentList "run start-server"; npm run start

注意:原生方法在日志输出、进程管理上不如concurrently便捷,优先推荐方法1。

内容的提问来源于stack exchange,提问作者mahavir jadhav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 03:34:54