{ "source": "doc/api/synopsis.markdown", "miscs": [ { "textRaw": "Synopsis", "name": "Synopsis", "type": "misc", "desc": "
The luvit CLI tool can be used as a scripting platform just like node. This can be used to run lua scripts as standalone servers, clients, or other tools.\n\n
\nThis simple web server written in Luvit responds with Hello World for every request.\n\n
\nlocal http = require('http')\n\nhttp.createServer(function (req, res)\n local body = "Hello world\\n"\n res:setHeader("Content-Type", "text/plain")\n res:setHeader("Content-Length", #body)\n res:finish(body)\nend):listen(1337, '127.0.0.1')\n\nprint('Server running at http://127.0.0.1:1337/')
\nTo run the server, put the code into a file called server.lua
and execute\nit with using luvit\n\n
> luvit server.lua\nServer running at http://127.0.0.1:1337/
\nThis script is a standalone HTTP server, there is no need for Apache or Nginx to act as host.\nAll of the examples in the documentation can be run similarly.\n
\n" } ] }