FMP Node API Documentation
Configuration
The FMP Node Wrapper supports multiple configuration options to suit different use cases and security requirements.
API Key Configuration
The FMP client supports three ways to provide your API key:
Option 1: Environment Variable (Recommended)
Set the FMP_API_KEY
environment variable and initialize without parameters:
1import { FMP } from 'fmp-node-api';
2
3// Automatically uses FMP_API_KEY from environment
4const fmp = new FMP();
Setup:
1# .env file
2FMP_API_KEY=your-api-key-here
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
Option 2: Direct Configuration
Provide the API key directly in the constructor:
1import { FMP } from 'fmp-node-api';
2
3const fmp = new FMP({
4apiKey: 'your-api-key-here',
5timeout: 10000, // optional
6});
Option 3: Mixed Configuration
Provide partial configuration and let the client fall back to environment variables:
1import { FMP } from 'fmp-node-api';
2
3const fmp = new FMP({
4timeout: 15000, // custom timeout
5// apiKey will be loaded from FMP_API_KEY environment variable
6});
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 |
Error Handling
The client provides clear error messages for configuration issues:
1try {
2const fmp = new FMP(); // No API key provided
3} catch (error) {
4console.error(error.message);
5// Output: "FMP API key is required. Please provide it in the config or set the FMP_API_KEY environment variable."
6}
Security Best Practices
1. Use Environment Variables
Always use environment variables for API keys in production:
1// ✅ Good - Environment variable
2const fmp = new FMP();
3
4// ❌ Bad - Hardcoded API key
5const fmp = new FMP({ apiKey: 'your-actual-key' });
2. Never Commit API Keys
Ensure your .env
file is in .gitignore
:
1# .gitignore
2.env
3.env.local
4.env.*.local
3. Use Different Keys for Different Environments
1# .env.development
2FMP_API_KEY=your-dev-key
3
4# .env.production
5
6FMP_API_KEY=your-prod-key
Environment-Specific Configuration
Development
1// Development with shorter timeout for faster feedback
2const fmp = new FMP({
3timeout: 5000,
4});
Production
1// Production with longer timeout for reliability
2const fmp = new FMP({
3timeout: 15000,
4});
Testing
1// Testing with mock API key
2const fmp = new FMP({
3apiKey: 'test-api-key-for-testing',
4timeout: 1000,
5});
Advanced Configuration
Multiple Client Instances
You can create multiple client instances with different configurations:
1// Client for real-time data
2const realtimeClient = new FMP({
3timeout: 5000,
4});
5
6// Client for historical data
7const historicalClient = new FMP({
8timeout: 30000,
9});
Troubleshooting
Common Issues
Issue: "FMP API key is required" error
Solution: Set the FMP_API_KEY
environment variable or provide it in the config
Issue: Environment variable not detected Solution:
- Ensure the variable is set correctly
- Restart your terminal/IDE
- Check for typos in the variable name
Issue: Timeout errors Solution: Increase the timeout value:
1const fmp = new FMP({
2timeout: 30000, // 30 seconds
3});
Debugging
Enable debug logging to troubleshoot configuration issues:
1import { FMP } from 'fmp-node-api';
2
3// Check if environment variable is set
4console.log('FMP_API_KEY exists:', !!process.env.FMP_API_KEY);
5
6const fmp = new FMP();
Next Steps
- Getting Started - Learn how to make your first API call
- API Reference - Explore all available endpoints
- Examples - See practical usage examples