# External Node.js Script / Server

> Use @aerostack/sdk in external Node.js scripts, CLIs, and backend services. Connect to your Aerostack project with a project API key.

Use `@aerostack/sdk` to build external scripts, CLIs, or backend services that need to talk to your Aerostack project.

## When to use this?

- **Migration Scripts**: Import data into your project.
- **Reporting Tools**: Fetch stats and generate reports.
- **External Webhooks**: Receive events from other platforms and update Aerostack.
- **Microservices**: Connect an existing Express/NestJS app.

## Installation

```bash
npm install @aerostack/sdk
```

## Example: Import Users Script

```typescript

const client = new AerostackClient({
  projectSlug: 'my-crm',
  baseUrl: 'https://api.aerostack.dev'
});

async function main() {
  // 1. Authenticate as Admin
  await client.auth.login(process.env.ADMIN_EMAIL, process.env.ADMIN_PASSWORD);
  
  // 2. Read CSV and Register Users
  fs.createReadStream('users.csv')
    .pipe(csv())
    .on('data', async (row) => {
      try {
        await client.auth.register({
          email: row.email,
          password: 'TemporaryPassword123!',
          name: row.name
        });
        console.log(`✅ Registered ${row.email}`);
      } catch (err) {
        console.error(`❌ Failed ${row.email}:`, err.message);
      }
    });
}

main();
```

  This runs on your laptop or server. It connects to the public Aerostack API over the internet.
