A quick server with bun
and expressJS
with typescript
mkdir express-with-bun
cd express-with-bun
bun init
and go through the wizard to create a new project ( just hit enter to accept the defaults )
bun install
bun install "@types/express" "express"
Note:
bun
will install the dependencies in thepackage.json
file just likenpm
oryarn
This sets up all the requirements
in index.ts
add the following code
import express, { Express, Request, Response } from 'express';
const app: Express = express();
const port = 30001;
app.get('/', (req: Request, res: Response) => {
res.send('Hello world!');
});
app.listen(port, () => {
console.log(`β‘οΈ[server]: Server is running at http://localhost:${port}`);
});
EXPLANATION: This is a simple express server that listens on port
30001
and returnsHello world!
when you hit the root url/
bun run index.ts
β‘οΈ[server]: Server is running at http://localhost:30001
navigate to http://localhost:30001
and you should see Hello world!
use
curl http://localhost:30001
to see the output in the terminal
here is a screenshot of the output