Before you can follow our TypeScript and Node.js how-to guides, you need to set up your development environment. This guide will walk you through creating a new project, installing essential packages, and configuring your environment.

1. Initialize Your TypeScript Project

First, create a new directory for your project and initialize it:
mkdir my-bags-project
cd my-bags-project
npm init -y
Next, install TypeScript and initialize the TypeScript configuration:
npm install -g typescript
npx tsc --init
This will create a tsconfig.json file with default settings, which you can customize as needed.

2. Install Core Dependencies

Now, install the core dependencies required for most interactions with the Bags API and for running your TypeScript code with Node.js.
npm install @bagsfm/bags-sdk dotenv @solana/web3.js bs58
Also, install the necessary development dependencies:
npm install -D typescript ts-node @types/node

3. Set Up Environment Variables

Create a .env file in your project root to store your Bags API key, Solana RPC URL, and other secrets:
# .env
BAGS_API_KEY=your_api_key_here
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
# PRIVATE_KEY=your_base58_encoded_private_key_here  # Required for guides that perform transactions
You can get your API key from dev.bags.fm. Some guides might require additional variables like your wallet’s private key for signing transactions.
Never commit your .env file to version control. Add it to your .gitignore file to keep your secrets safe.

4. Project Structure

Your project structure should look like this:
my-bags-project/
├── package.json
├── tsconfig.json
├── .env
├── .gitignore
└── src/
    └── (your TypeScript files will go here)
Make sure to add .env to your .gitignore file:
# .gitignore
.env
node_modules/
dist/
You are now ready to follow our how-to guides! Each guide will include the complete setup code needed to initialize the SDK and run the examples.