A quick server with bun and expressJS with typescript
mkdir express-with-bun
cd express-with-bun
bun initand go through the wizard to create a new project ( just hit enter to accept the defaults )
bun install
bun install "@types/express" "express"Note:
bunwill install the dependencies in thepackage.jsonfile just likenpmoryarn
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
30001and returnsHello world!when you hit the root url/
bun run index.tsβ‘οΈ[server]: Server is running at http://localhost:30001navigate to http://localhost:30001 and you should see Hello world!
use
curl http://localhost:30001to see the output in the terminal
here is a screenshot of the output


