A simple express api with bun.sh
https://bun.sh/guides/ecosystem/express
# install bun
curl -fsSL https://bun.sh/install | bash
# install dependencies
bun install
# run the dev server
bun dev
# build
bun build:bun
Set the bun environment to development or production in the .env
file.
NODE_ENV=development
For more info on how bun handles environments see:
see the docs for the test runner: https://bun.sh/docs/cli/test
bun test
# build the app
bun build:bun
# build with docker
docker build . --tag bun-express
# start the docker container
docker run -d -p 3000:3000 bun-express
# view it running on localhost
curl localhost:3000
This is currently setup to use MongoDB. If you would like to switch the provider then take a look at the prisma docs
You can replace DATABASE_URL
with your mongodb connection string whether that be cloud or locally hosted.
Note: when using Prisma the MongoDB database connector uses transactions to support nested writes. Transactions require a replica set deployment. The easiest way to deploy a replica set is with Atlas. It's free to get started.
https://www.prisma.io/docs/concepts/database-connectors/mongodb
https://bun.sh/guides/ecosystem/prisma
You will need to generate the models after you make changes to the schema.prisma file or the first time you run the app.
bunx prisma generate
bun seed