Table of Contents
Are you ready to start your journey with Bun, the modern JavaScript runtime? This quick tutorial will guide you through creating your first Bun project with TypeScript support, making it easier to build robust and type-safe applications.
Prerequisites
- Node.js installed on your machine (version 14 or higher)
- Basic knowledge of JavaScript and TypeScript
- Internet connection to download Bun
Installing Bun
To begin, install Bun by running the following command in your terminal:
curl -fsSL https://bun.sh/install | bash
Once installed, verify the installation with:
bun --version
Creating a New Bun Project with TypeScript
Navigate to the directory where you want your project and run:
bun init my-typescript-project --template typescript
This command creates a new project folder with TypeScript support already configured.
Understanding the Project Structure
Inside your project folder, you’ll find:
- src/index.ts: The main TypeScript file where you’ll write your code.
- package.json: Contains project dependencies and scripts.
- tsconfig.json: TypeScript configuration file.
Writing Your First TypeScript Code
Open src/index.ts and add the following code:
console.log('Hello, Bun with TypeScript!');
Running Your Project
To run your project, use the command:
bun run
You should see Hello, Bun with TypeScript! printed in your terminal.
Next Steps
Now that your project is set up, you can start adding more TypeScript files, install dependencies, and build your application. Bun makes it easy to develop with modern JavaScript and TypeScript features.
Happy coding!