GitHub Actions issue: Server running in the foreground instead of background

GitHub Actions issue: Server running in the foreground instead of background

I’ve had an issue where the workflow got stuck in terms that it kept running in the same step without moving to the next step.

Here is the YML code part where the workflow is stuck:

- name: Start Application
  run: node src/index.js

The workflow resutls indicated that the localhost:5002 and the Mongoose server were running, and it just kept running without moving to the next step. Take a look:

Run node src/index.js
  node src/index.js
  shell: /usr/bin/bash -e {0}
  env:
    DATABASE_URL: ***
    SESSION_SECRET: ***
    EMAIL_USER: ***
    EMAIL_PASS: ***
    PORT: 5002
Server running on port 5002
Mongoose connected

What is the issue here?

By default, node src/index.js runs in the foreground, meaning GitHub Actions waits for it to complete, which in this case never happens since the step isn’t about installing a feature but about continuously running.

The solution for this issue is to run it in the background.

Applying the solution in this case is actually super simple. We just have to update the Start Application action with the & command. Here is how:

- name: Start Application
  run: node src/index.js & 

Scroll to Top