{"id":20279060,"url":"https://github.com/t-vk/nodemcu-express","last_synced_at":"2025-08-20T15:40:37.956Z","repository":{"id":107367289,"uuid":"89820757","full_name":"T-vK/NodeMCU-Express","owner":"T-vK","description":"HTTP Web Server library for ESP8266 modules that run the NodeMCU firmware. (Acts like express.js from node.js, but with Lua instead of JavaScript.)","archived":false,"fork":false,"pushed_at":"2019-06-20T08:11:10.000Z","size":18,"stargazers_count":19,"open_issues_count":3,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T06:14:38.912Z","etag":null,"topics":["esp8266","express","expressjs","http-server","lua","nodemcu","web-server"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/T-vK.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-30T00:33:12.000Z","updated_at":"2023-12-09T12:05:09.000Z","dependencies_parsed_at":"2023-05-30T08:15:54.923Z","dependency_job_id":null,"html_url":"https://github.com/T-vK/NodeMCU-Express","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/T-vK%2FNodeMCU-Express","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/T-vK%2FNodeMCU-Express/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/T-vK%2FNodeMCU-Express/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/T-vK%2FNodeMCU-Express/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/T-vK","download_url":"https://codeload.github.com/T-vK/NodeMCU-Express/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351393,"owners_count":21089272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esp8266","express","expressjs","http-server","lua","nodemcu","web-server"],"created_at":"2024-11-14T13:27:58.938Z","updated_at":"2025-04-11T06:14:44.635Z","avatar_url":"https://github.com/T-vK.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Express.js-like HTTP server library for NodeMCU\n\n## About\nThis HTTP server library is very similar to the popular node.js module [express.js](https://expressjs.com/en/starter/hello-world.html).  \nIt's extremely intuitive and easy to use thus and I'm making the interface as similar as possible.  \nThe library is written in Lua.\n\n## Features (current and upcoming)\n[Go to the project site.](https://github.com/T-vK/NodeMCU-Express/projects/1)\n\n## Serving files\nServing files is really easy and can be done with a single line of code.\nExample of serving the file `home.html` at url `/home`:  \n``` Lua\napp:use('/home',express.static('home.html'))\n```\nTo serve all files that are in a certain directory, let's say the directory is called `foo`, you can do:  \n``` Lua\napp:use('/example',express.static('foo'))\n```\nIf you have a file called `foo/test.html` on your ESP8266 module and it's IP is 192.168.1.10, then you will be able to access it by visiting `http://192.168.1.10/example/text.html`.\n\n## Routes\nA route consists of a URL path and a function. Whenever someone visits the URL path, the function gets called.  \nFor instance:  \n``` Lua\n-- Create a new route at `/led-on` an the connected function turns an LED on\napp:get('/led-on',function(req,res)\n    gpio.write(4, gpio.HIGH) -- set GPIO 2 to HIGH\n    res:send('Led turned on!')\nend)\n```\nWe always start our path with `/`. If your ESP8266 has the IP 192.168.1.111 then you can open the route `/led-on` by typing `http://192.168.1.111/led-on` into your browser.\n\n## Middlewares\nA middleware consists of a function that gets called every time someone make an http request to our ESP8266 module.  \nUsing a middleware we can easily extend the functionality of our http server.  \nFor instance to add a cookie parser, a request logger, an authentication mechanism and muuuuuch more.  \nHere is an example for a request logger:  \n``` Lua\napp:use(function(req,res,next) \n    print('New request!' .. ' Method: ' .. req.method .. ' URL: ' .. req.url)\n    next()\nend)\n\n```\n\n## Example\nFor a full example go here: [example.lua](example.lua)\n\nHere is the short version:\n``` Lua\nrequire('HttpServer')\n\nlocal app = express.new()\napp:listen()\n\n-- Define a new middleware that prints the url of every request\napp:use(function(req,res,next) \n    print(req.url)\n    next()\nend)\n\n-- Define a new route that just returns an html site that says \"HELLO WORLD!\"\napp:get('/helloworld',function(req,res)\n    res:send('\u003chtml\u003e\u003chead\u003e\u003c/head\u003e\u003cbody\u003eHELLO WORLD!\u003c/body\u003e\u003c/html\u003e')\nend)\n\n-- Serve the file `home.html` when visiting `/home`\napp:use('/home',express.static('home.html'))\n\n-- Serve all files that are in the folder `http` at url `/libs/...`\n-- (To be more accurate I'm talking about all files starting with `http/`.)\napp:use('/libs',express.static('http'))\n```\nOf course your ESP8266 needs to be connected to your WiFi or your ESP8266 has to host an AP that you are connecting to.\n\n## How to use it\nJust upload `HttpServer.lua` to your ESP8266, then you can use `require('HttpServer') just like in my example in your `init.lua`.\n\n## Need help? Have a feature request? Found a bug?\nCreate an issue right here on github.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft-vk%2Fnodemcu-express","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ft-vk%2Fnodemcu-express","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft-vk%2Fnodemcu-express/lists"}