How to access a node server that is started on first step of pipeline, in second step?
Asked by Shreejan Regmi:

**What I want to do:**   

I want to start a backend node.js server in step 1 of my pipeline (port 5000); and from the second step of the pipeline, I want to call one of its public endpoint.

<br />

**The scenario:**   
I have two repos, one for frontend, and the other for backend. The yml file is present in the frontend repo and I have made all configurations in bitbucket to provide my frontend pipeline the access to clone my backend repo, so all good on that. The server also starts fine on the first step:  
![bb-community-3.png](/t5/image/serverpage/image-id/232634iF02BE09E99D3B047/image-size/large?v=v2&px=999 "bb-community-3.png")  

**My YML:**   
![bb-community-2.png](/t5/image/serverpage/image-id/232633i199FA0B5D043C604/image-size/large?v=v2&px=999 "bb-community-2.png")

**The issue**

In the second step, when I curl GET the public endpoint e.g: <http://localhost:5000/search>, I get the error:

    curl: (7) Failed to connect to localhost port 5000: Connection refused

Screenshot:  

![bb-community-1.png](/t5/image/serverpage/image-id/232632i306F90F65E0E1484/image-size/large?v=v2&px=999 "bb-community-1.png")  

<br />

I think this is because when we get to step 2 the build in step 1 is already torn down so the server is not available?   

**How can I access the endpoint in second step so that the curl request passes?**   

<br />

Thanks for any help, much appreciated.


Answers:
author: Theodora Boudale
body: Hi [@Shreejan Regmi](/t5/user/viewprofilepage/user-id/5111191) and welcome to the community!

Pipelines builds run in Docker containers. For each step of your build, a Docker container starts, the repo is cloned in that container, and then the commands from the step's script are executed. When the commands finish successfully or if a certain command fails, the Docker container gets destroyed.

What you are asking is not possible because the Docker container from the first step no longer exists when the second step runs. You will need to start the server in the same step where you want to use it.

Please also keep in mind that if you clone a different repo in the first step, that clone will not be available in the second step. You can make use of artifacts for any files that are generated or downloaded during a step if you want them to become available in subsequent steps:

* <https://support.atlassian.com/bitbucket-cloud/docs/use-artifacts-in-steps/>

If you have any other questions, please feel free to reach out.

Kind regards,  
Theodora

comments: author: Shreejan Regmi
body: Hi Theodora, thanks for your help, starting both in the same step did work :)   

I am wondering though... if the backend server and frontend app needs two different versions of node to install and run, how can I manage that in the same step? Do I use a version manager such as nvm or volta, or do you suggest any other proper way?   

<br />


author: Theodora Boudale
body: Hi Shreejan,

Thank you for the update, it's good to hear that this worked!
> I am wondering though... if the backend server and frontend app needs two different versions of node to install and run, how can I manage that in the same step? Do I use a version manager such as nvm or volta, or do you suggest any other proper way?

If the tests you do for the backend are independent from the tests for the frontend, you could use a version manager. Another option would be to test the backend in one step and the frontend in a different step, and use a different Docker image as a build container for each step in your bitbucket-pipelines.yml file (with each image using a different node version).

Kind regards,  
Theodora


author: Erez Maadani
body: Hey [@Shreejan Regmi](/t5/user/viewprofilepage/user-id/5111191)

Like you mentioned, the process might be killed at this point, and further-more, the second process might not be running on the same host/container.

The safer approach would to either run the two servers in the same step or run the servers on a dedicated runner which can host the servers.

**Note**: the second approach is far less recommended because it would make life very complicated when trying to run your builds in parallel

comments: author: Shreejan Regmi
body: Thanks Erez! It worked when I started both of the servers in the same step. :)


Tags: bitbucket-cloud

cloud