# Run server before test

**URL:** <https://discuss.circleci.com/t/run-server-before-test/12052>\
**Category:** Programming Languages\
**Tags:** nodejs\
**Created:** [April 19, 2017, 9:52am UTC](https://discuss.circleci.com/t/run-server-before-test/12052 "2017-04-19T09:52:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Passero](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@Passero](https://discuss.circleci.com/u/Passero)\
**Post date:** [April 19, 2017, 9:52am UTC](https://discuss.circleci.com/t/run-server-before-test/12052/1 "2017-04-19T09:52:05Z")

</div>

I am new to circleCI and build a very simple “hello world” app to get myself familiar with circleCI.

In my app I have a mocha test that requests the “/” resource and checks the status code. In order for that test to work, the node app needs to be running.

Can this be done in circleCI or can this only be done by first building a docker container, running the container and afterwards executing the tests?

At the moment the test fails because he cannot connect to the server.

I even tried adding this to the circle.yml but still it fails although the server has been started…

test:  
pre:  
- node main &

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [April 20, 2017, 8:48pm UTC](https://discuss.circleci.com/t/run-server-before-test/12052/2 "2017-04-20T20:48:25Z")

</div>

This can be done on CircleCI no problem. More of your `circle.yml` file and/or more explaination of what you’re doing will help.

Have you already seen our [NodeJS doc](https://circleci.com/docs/1.0/language-nodejs/)?

---

<div class="post-metadata">

**Author:** ![Passero](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@Passero](https://discuss.circleci.com/u/Passero)\
**Post date:** [April 20, 2017, 9:33pm UTC](https://discuss.circleci.com/t/run-server-before-test/12052/3 "2017-04-20T21:33:49Z")

</div>

Do you mind explaining how? I’ve looked through the documentation and that’s where I found out I could execute pre test scripts. So that’s why I added  
test:  
pre:

- node main &  
to the circle.yml (it’ the only thing in the file) and the logs shows the server was running but still my mocha test failed because it could not connect to localhost:3001

---

<div class="post-metadata">

**Author:** ![defionscode](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/defionscode/32/12671_2.png) [@defionscode](https://discuss.circleci.com/u/defionscode)\
**Post date:** [October 18, 2017, 1:44pm UTC](https://discuss.circleci.com/t/run-server-before-test/12052/4 "2017-10-18T13:44:03Z")

</div>

Have you tried this? [https://circleci.com/docs/1.0/background-process/](https://circleci.com/docs/1.0/background-process/)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:33am UTC](https://discuss.circleci.com/t/run-server-before-test/12052/5 "2018-06-18T11:33:11Z")

</div>


