Prerequisites
Before you begin, ensure you have:- Node.js 22.x or higher installed
- A Stripe account (sign up for free)
- Your Stripe API keys (test mode recommended for development)
- A code editor and terminal
Installation
Clone or download the project
If you haven’t already, get the project files and navigate to the directory:
Install dependencies
Install all required packages using your preferred package manager:This installs:
- Express server framework
- Stripe Node.js SDK (v11.6.0)
- CORS and body parsing middleware
- Swagger for API documentation
- Development tools (nodemon, jest)
Configure environment variables
Create a Open
.env file in the root directory by copying the example:.env and add your Stripe credentials:.env
Get your test API keys from the Stripe Dashboard. Use test keys (starting with
sk_test_) for development.Start the development server
Launch the API server with hot reloading:You should see:The API is now available at
http://localhost:3000Make Your First API Call
Let’s create a customer in your Stripe account:Review the response
You should receive a successful response:Save the
id field - you’ll need it for creating payments.Verify in Stripe Dashboard
Log into your Stripe Dashboard and navigate to Customers. You should see your newly created customer.
Create a Payment
Now let’s create a payment intent for the customer:The
amount is in your currency’s base unit (e.g., dollars/euros). The API automatically converts it to cents (multiplies by 100) before sending to Stripe.Next Steps
Authentication
Learn about API keys and security best practices
API Reference
Explore all available endpoints and parameters
Webhooks
Set up webhook handling for real-time events
Error Handling
Understand error responses and status codes
Testing with Stripe Test Cards
Stripe provides test card numbers for different scenarios:| Card Number | Scenario |
|---|---|
4242424242424242 | Successful payment |
4000000000000002 | Card declined |
4000002500003155 | Requires authentication (3D Secure) |