2

I have a requirement to run both my angular application and JSON-server simultaneously when I run "ng serve" or "npm run start", rather than having to start each one separately.

How do I modify the startup scripts to do so? Note: This is running in Windows.

Edit: I've changed the start script in my package.json to the following, but it only starts up json-server, not the Angular application:

"start": "json-server --watch db.json && ng-serve",

Solution: I ended up solving this by installing ```npm-run-all``, and adding new entries to the scripts in package.json:

  1. "json-server" : "json-server --watch db.json"
  2. "serve" : "ng serve"
  3. "start" : "run-p json-server serve"

I never figured out why "&&" didn't work.

1

3 Answers 3

2

It Worked for me like this,

in package.json

"start": "json-server --watch db.json & ng serve"

then i used,

npm run start

And it worked for me like this.

Sign up to request clarification or add additional context in comments.

Comments

1

Did you try using:

"start": "json-server --watch db.json & ng-serve",

with a single & ?

if command1 succeeds then execute command2 (IF) -> command1 && command2

Execute command1 and then execute command2 (AND) -> command1 & command2

Execute command2 only if command1 fails (OR) -> command1 || command2

Your json-server maybe is not "returning" a "success" code

1 Comment

Yes, I've tried both & and &&. Basically, it runs the first command but not the second. Your idea of not returning a success code makes a lot of sense, but I still need both to run with a single command.
1

I think it's simple to explain.

&& = sequential execution

& = parallel execution

And the reason why your 'ng serve' was not executed is by the fact, that it only executes when the first script has completed.

In your case you're starting a json-server, but the server is running and watching the db.json file, which means this program never ends. So the ng serve will not be executed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.