# I am noob, how do I keep the HTTP server running if I want to start it from the command line?

**URL:** https://discourse.julialang.org/t/i-am-noob-how-do-i-keep-the-http-server-running-if-i-want-to-start-it-from-the-command-line/95136
**Category:** Web Stack
**Created:** [February 24, 2023, 1:40pm UTC](https://discourse.julialang.org/t/i-am-noob-how-do-i-keep-the-http-server-running-if-i-want-to-start-it-from-the-command-line/95136 "2023-02-24T13:40:44Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [February 24, 2023, 1:40pm UTC](https://discourse.julialang.org/t/i-am-noob-how-do-i-keep-the-http-server-running-if-i-want-to-start-it-from-the-command-line/95136/1 "2023-02-24T13:40:44Z")

</div>

I have a very simple HTTP server that I want to run

# **server.jl**

> ****
>
> ```julia
> using Pkg
> 
> Pkg.add("HTTP")
> 
> using HTTP
> 
> # if false
> ENV["PORT"] = "8080"
> # end
> 
> print(ENV["PORT"])
> 
> const PORT = parse(Int, ENV["PORT"])
> 
> using HTTP
> 
> # HTTP.listen! and HTTP.serve! are the non-blocking versions of HTTP.listen/HTTP.serve
> server = HTTP.serve!(PORT) do request::HTTP.Request
> @show request
> @show request.method
> @show HTTP.header(request, "Content-Type")
> @show request.body
> try
> return HTTP.Response("Hello")
> catch e
> return HTTP.Response(400, "Error: $e")
> end
> end
> 
> #close(server)
> 
> ```

So I try to trigger it using `julia server.jl` from bash and it seems to close instantly.

I am very new to this web things, what do I need to do to keep this server running so I can test it by sending request to it?

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [February 24, 2023, 2:00pm UTC](https://discourse.julialang.org/t/i-am-noob-how-do-i-keep-the-http-server-running-if-i-want-to-start-it-from-the-command-line/95136/2 "2023-02-24T14:00:27Z")

</div>

Either use the blocking call or put in a long `sleep` or something else which keeps your script from exiting.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [February 24, 2023, 2:19pm UTC](https://discourse.julialang.org/t/i-am-noob-how-do-i-keep-the-http-server-running-if-i-want-to-start-it-from-the-command-line/95136/3 "2023-02-24T14:19:11Z")

</div>

you can `julia -i script.jl` so it drops you into interactive session after loading the script

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [February 24, 2023, 2:51pm UTC](https://discourse.julialang.org/t/i-am-noob-how-do-i-keep-the-http-server-running-if-i-want-to-start-it-from-the-command-line/95136/4 "2023-02-24T14:51:58Z")

</div>

I want to eventually run this from docker. Yeah so no need to drop into an interactive session

---

<div class="post-metadata">

### Author: ![AMJ](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amj/32/214096_2.png) [@AMJ](https://discourse.julialang.org/u/AMJ)
#### Post date: [February 24, 2023, 7:28pm UTC](https://discourse.julialang.org/t/i-am-noob-how-do-i-keep-the-http-server-running-if-i-want-to-start-it-from-the-command-line/95136/5 "2023-02-24T19:28:04Z")

</div>

Put `wait(Condition())` at the end of the script and it will stay open.

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [February 24, 2023, 7:46pm UTC](https://discourse.julialang.org/t/i-am-noob-how-do-i-keep-the-http-server-running-if-i-want-to-start-it-from-the-command-line/95136/6 "2023-02-24T19:46:43Z")

</div>

You can just `wait(#= for the =# server)`.

---

<div class="post-metadata">

### Author: ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)
#### Post date: [February 24, 2023, 9:47pm UTC](https://discourse.julialang.org/t/i-am-noob-how-do-i-keep-the-http-server-running-if-i-want-to-start-it-from-the-command-line/95136/7 "2023-02-24T21:47:01Z")

</div>

Yeah, you can call `wait(server)` or just don’t use the `HTTP.serve!` bang version and use the blocking version like `HTTP.serve(...)`
