Getting Started
Welcome to the FMP Node Wrapper! This guide will help you get up and running quickly.
Installation
Install the package using pnpm (recommended):
1pnpm add fmp-node-api
Or using npm:
1npm install fmp-node-api
Or using yarn:
1yarn add fmp-node-api
API Key Setup
To use the FMP Node Wrapper, you'll need an API key from Financial Modeling Prep:
- Visit Financial Modeling Prep (opens in new tab)
- Sign up for an account
- Navigate to your dashboard to get your API key
Basic Setup
Here's how to initialize the client:
1import { FMP } from 'fmp-node-api';
2
3// Option 1: Use environment variable (recommended)
4const fmp = new FMP(); // Automatically uses FMP_API_KEY from environment
5
6// Option 2: Provide API key directly
7const fmp = new FMP({
8apiKey: 'your-api-key-here',
9timeout: 10000, // optional, default 10s
10});
11
12// Option 3: Mixed configuration
13const fmp = new FMP({
14timeout: 15000, // custom timeout, apiKey from FMP_API_KEY env var
15});
Configuration Options
The FMP
client accepts the following configuration options:
Option | Type | Default | Description |
---|---|---|---|
apiKey | string | FMP_API_KEY env var | Your FMP API key (optional if env var is set) |
timeout | number | 10000 | Request timeout in milliseconds |
Your First API Call
Let's make your first API call to get a stock quote:
1// Get real-time stock quote
2const quote = await fmp.quote.getQuote({ symbol: 'AAPL' });
3
4if (quote.success && quote.data) {
5console.log('Stock Price:', quote.data.price);
6console.log('Change:', quote.data.change);
7console.log('Market Cap:', quote.data.marketCap);
8} else {
9console.error('Error:', quote.error);
10}
Response Format
All API methods return a consistent response format:
1interface ApiResponse<T> {
2 success: boolean;
3 data: T | null;
4 error: string | null;
5 status: number;
6}
success
: Boolean indicating if the request was successfuldata
: The response data (null if unsuccessful)error
: Error message string (null if successful)status
: HTTP status code
Error Handling
Always check the success
property before accessing the
data:
1const response = await fmp.quote.getQuote({ symbol: 'INVALID' });
2
3if (response.success && response.data) {
4// Handle successful response
5console.log(response.data);
6} else {
7// Handle error
8console.error('Error:', response.error);
9console.error('Status:', response.status);
10}
Environment Variables
For security, store your API key in environment variables. The FMP client automatically detects the FMP_API_KEY
environment variable:
1import { FMP } from 'fmp-node-api';
2
3// Simply initialize without any parameters
4const fmp = new FMP(); // Automatically uses FMP_API_KEY from environment
5
6// The client will throw a clear error if no API key is found:
7// "FMP API key is required. Please provide it in the config or set the FMP_API_KEY environment variable."
Create a .env
file in your project root:
1# Your FMP API key (get one at https://financialmodelingprep.com/developer)
2FMP_API_KEY=your-api-key-here
Or set it in your system environment:
1# Linux/macOS
2export FMP_API_KEY=your-api-key-here
3
4# Windows PowerShell
5
6$env:FMP_API_KEY="your-api-key-here"
7
8# Windows Command Prompt
9
10set FMP_API_KEY=your-api-key-here
⚠️ Security Note: Never commit your .env
file to version control. It should already be in your .gitignore
.
💡 Pro Tip
All code blocks in this documentation include a copy button that appears when you hover over them. Click the copy icon to quickly copy the code to your clipboard!
Next Steps
Now that you have the basics set up, explore:
- Configuration - Detailed configuration options and best practices
- API Reference - Complete endpoint documentation
- Stock Endpoints - Stock-specific API methods
- Financial Endpoints - Financial statement methods
- Examples - Practical code samples
Common Issues
API Key Issues
- Make sure your API key is valid and active
- Check your FMP account for any usage limits
- Verify the API key is correctly passed to the client
Network Issues
- Check your internet connection
- Verify the base URL is accessible
- Consider increasing the timeout for slower connections
TypeScript Issues
- Ensure you're using TypeScript 4.5+ for best type support
- All types are included in the main package
Ready to explore the API? Check out the API Reference for detailed endpoint documentation.