Bun.sh is a modern JavaScript runtime similar to Node.js, but it promises better performance and built-in tools for tasks such as bundling, transpiling, and running scripts.
10 Facts about Bun.sh
- Bun.sh is a modern JavaScript runtime designed for better performance than Node.js.
- It includes built-in tools for bundling, transpiling, and running scripts.
- Bun.sh supports hot reloading, making development faster and easier.
- It can directly run both JavaScript and TypeScript files without separate compilation steps.
- Bun.sh uses the npm ecosystem for managing dependencies.
- The installation of Bun.sh can be done via a simple curl command or through npm.
- Bun.sh aims to simplify the development workflow with integrated tools and faster execution.
- It is designed to work seamlessly with existing JavaScript and TypeScript projects.
- Bun.sh provides a command-line interface for initializing new projects and managing builds.
- Its built-in bundler can create production-ready builds from your source code.
1. Install Bun.sh
To install Bun.sh, you'll need to run the following script from your terminal:
for powershell(sh)
curl -fsSL https://bun.sh/install | bash
Basic commands in bun.sh
- ## Initialize a new project
For init a new project in powershell(sh)
bun init
This sets up a new project directory with the necessary files.
2. Run a JavaScript or TypeScript file:
bun run <file>
For example, to run index.js
//eg file name index.js
bun run index.js
3. Install dependencies:
bun install <package-name>
Eg: To install express
bun install express
4. Add Dependency to your Project
bun add <package-name>
This will add the package to your package.json and install it.
5. Remove a dependency from your project:
bun remove <package-name>
6. Bundle your code:
bun bundle <file>
For example, to bundle index.js:
bun bundle index.js
7.Run the project with hot reloading:
bun run --hot <file>
For example, to run server.js with hot reloading:
bun run --hot server.js
8.Check the Bun.sh version:
bun --version
9.Build your project for production:
bun build
This will create a production build of your project.
10. Update Bun.sh to the latest version:
bun upgrade
These commands cover the basic functionalities you will use when working with Bun.sh, from initializing projects and running files to managing dependencies and building for production.
Top comments (0)