Installation and Setup
Prerequisites
- Node.js 18+
- npm, pnpm, yarn, bun, or any other package manager
- TypeScript (recommended)
- Patience (optional, but highly recommended)
Installation
- Install Switchblade and the desired validation library. You only need to install the one you plan to use, but if you want to use all, what are we to judge? 🤷♂️😏
bash
npm install @takodotid/switchblade zodbash
npm install @takodotid/switchblade @sinclair/typebox- Install the desired adapter.
bash
npm install hono @hono/node-serverProject Setup
1. Create a New Project
bash
mkdir switchblade-app
cd switchblade-app
npm init -y2. Install Dependencies
See Installation for the required dependencies.
3. TypeScript Configuration
Create a tsconfig.json, here's the recommended configuration:
json
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"strict": true,
"esModuleInterop": true
}
}4. First Switchblade App
See Quick Example for a simple example of how to use Switchblade.
5. Add Scripts to package.json
Run Typescript using tsx library
To get started quickly, we recommend using the tsx library to run TypeScript files directly. With it, you can run TypeScript files without needing to compile them first.
json
{
"scripts": {
"start": "tsx index.ts",
"dev": "tsx watch index.ts"
}
}Running the Application
bash
npm dev # Will restart the server on changes