Bun
Bun (opens in a new tab) is a fast all-in-one JavaScript/TypeScript runtime that ships as a single executable. Bun is a drop-in replacement for Node.js and designed for performance (startup times and memory usage are order of magnitude faster than the alternatives).
Install Bun
curl -fsSL https://bun.sh/install | bash
Create new project with Bun
bun create
creates a new Websi project using the websi
template and installs required dependencies.
bun create websi my-websi-app
Here's the directory structure created using bun create
:
my-websi-app
├── bun.lockb
├── node_modules
├── README.md
├── main.ts
├── package.json
└── tsconfig.json
Basic web server
Open main.ts
import { Server } from 'websi'
import { GET } from 'websi/route'
import * as Response from 'websi/response'
const routes = [
GET('/', () => Response.OK('Hello, Websi!'))
]
const server = Server(routes)
export default server
Start the project
Websi template adds a start
script to the scripts
section in package.json
. Thus, to start the project you can just run:
bun start
Hot reloading is automatically enabled, so you don't need to restart your server while developing and changing files.
By default, the project starts on port 4000
. Open http://localhost:4000 (opens in a new tab) in your browser to see the result.
Add new route
Open main.ts
again and add the highlighted lines
import { Server } from 'websi'
import { GET } from 'websi/route'
import * as Response from 'websi/response'
const routes = [
GET('/', () => Response.OK('Hello, Websi!')),
GET('/json', () => {
return Response.Created({ foo: 1, bar: 'baz' });
})
]
const server = Server(routes)
export default server
You can now test it by opening https://localhost:4000/json (opens in a new tab) in your browser.
Deploy
Coming soon! i.e. once Bun adds their deployment solution :)