Skip to content

Instantly share code, notes, and snippets.

@sheharyarn
Created June 3, 2022 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheharyarn/38eabea649bfc76947dfbee265064fe5 to your computer and use it in GitHub Desktop.
Save sheharyarn/38eabea649bfc76947dfbee265064fe5 to your computer and use it in GitHub Desktop.
Simple Elixir Server as a Script
Mix.install([{:plug_cowboy, "~> 2.0"}])
defmodule Server do
use Plug.Router
plug(:match)
plug(:dispatch)
match _ do
send_resp(conn, 200, "Hello World!")
end
end
if System.argv() == ~w[server] do
Plug.Cowboy.http(Server, [], port: 4000)
System.no_halt(true)
end
# To install dependencies, just run: elixir app.exs
# To start server, run: elixir app.exs server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment