Light is currently in development! Please note there may be breaking changes in between minor and beta versions! We will adhere to semantic versioning starting with v2.0.0
Getting started is quick and easy! This guide assumes you are running the latest LTS version of node. There is also a live example at the bottom if you want to try out light without setting it up locally!
Initialize a new repository with
npm init. Then install light.
Then add the following scripts to your
Once you have installed light, all
.js files under the
routes directory will automatically be imported. Typescript will be automatically run/compiled if there is a
tsconfig.json in the root directory. Additionally, all files that end in
.test.(t|j)s and files in
__tests__ folders will be ignore.
To get started, lets populate
routes/index.js. Please note we use Next.js style routing. You can check out the routing docs on the left for more information.
This is probably different that what you are used to with
hapi, etc. There are a few interesting parts to this file. The
createRoute function is the core of light and it returns an object containing
DELETE, and a bunch of other HTTP methods. For each route you can add whatever methods you like to support. Any methods you do not define will return
404 Not Found. At the bottom we export
route is an object containing all of the information needed to execute your code. If the server is started with the CLI, it will transform that object and inject it in the router, but if it is run in a serverless environment, it will transform it into a request handler.
Once you are done editing the file, run
npm run dev to start the server with hot module reloading. If you did everything right, your terminal should output something similar to this.
Phew, that was a lot. Don't worry though, you just learnt about 80% of light! It's really that simple. You now have a dev server that
- hot swaps any code you change without restarting the server
- can support many different serverless and hosting platforms
- has very little magic behind the scenes, what you see in a route is what you get
Feel free to continue with the guides in the sidebar to understand more of the framework!
If you want to mess around with the example provided above without setting it up on your computer, you can try it out on RunKit! Just edit the code below and click the URL in the bottom right.