Build AI-powered JavaScript applications using Node.js and the Claude API. Day 1 covers project setup, your first API call, and the basics of message handling.
JavaScript is the language of the web. If you want to build AI-powered web apps — chatbots, writing tools, document processors — JavaScript is the fastest path from idea to deployed product. The Claude API has a first-class Node.js SDK, and the same code runs on the frontend and backend.
mkdir ai-js-app && cd ai-js-app npm init -y npm install @anthropic-ai/sdk dotenv touch .env index.js
ANTHROPIC_API_KEY=sk-ant-your-key-here
import Anthropic from '@anthropic-ai/sdk';
import * as dotenv from 'dotenv';
dotenv.config();
const client = new Anthropic();
async function chat(userMessage) { const message = await client.messages.create({ model: 'claude-opus-4-5', max_tokens: 1024, messages: [ { role: 'user', content: userMessage } ] }); return message.content[0].text;
}
// Test it
const reply = await chat('Explain async/await in JavaScript in 3 sentences.');
console.log(reply); { "type": "module", "scripts": { "start": "node index.js" }
} node index.js
const message = await client.messages.create({ ... });
console.log(message.id); // msg_xxx
console.log(message.model); // claude-opus-4-5
console.log(message.stop_reason); // end_turn
console.log(message.usage.input_tokens); // tokens used
console.log(message.usage.output_tokens); // tokens generated
console.log(message.content[0].type); // 'text'
console.log(message.content[0].text); // the actual reply Before moving on, make sure you can answer these without looking: