Cozy Threads is a direct-to-consumer ecommerce platform showcasing high-quality, ethically-sourced apparel and accessories. This demo application demonstrates the integration of Stripe for payment processing in a full-stack web application using React for the frontend and Node.js/Express for the backend, all within a TypeScript environment.
You can view the live application here.
Before you begin, ensure you have the following installed on your system:
- Node.js (v20.x or later)
- npm (v6.x or later)
To run this application locally and perform test transactions, follow these steps:
- Node.js and npm installed on your machine. You can download them from Node.js.
-
Clone the Repository:
git clone https://github.com/dgavigan/cozy-threads cd cozy-threads -
Install Dependencies:
npm install
-
Set Up Environment Variables:
Create two
.envfiles: one in theclientdirectory and one in theserverdirectory.Client
.envfile (client/.env):REACT_APP_STRIPE_PUBLIC_KEY=your_stripe_public_key API_BASE_URL=http://localhost:8080
API_BASE_URL is NOT required when building for production
Server
.envfile (server/.env):STRIPE_SECRET_KEY=your_stripe_secret_key
-
Run the Application:
Use the unified script to start both the server and client:
npm run start:dev
This script will start both the Express server and the React client. Your application should now be running at
http://localhost:3000.
To perform test transactions, you can use Stripe's test cards. Visit Stripe's Test Card Numbers for a list of test card numbers.
Here are some example test cards you can use:
- Visa: 4242 4242 4242 4242
- Mastercard: 5555 5555 5555 4444
- American Express: 3782 822463 10005
When performing test transactions, use any future date for the expiration date and any three-digit CVC (four digits for American Express).
To configure the application with your Stripe account:
-
Log in to Your Stripe Dashboard:
Visit Stripe Dashboard and log in to your account.
-
Obtain API Keys:
Navigate to Developers > API keys. Copy the Publishable key and Secret key.
-
Set Environment Variables:
Update your
.envfiles with the keys you obtained from the Stripe Dashboard:Client
.envfile (client/.env):REACT_APP_STRIPE_PUBLIC_KEY=your_stripe_public_key REACT_APP_SERVER_URL=http://localhost:8080
Server
.envfile (server/.env):STRIPE_SECRET_KEY=your_stripe_secret_key
-
Restart Your Application:
If your application is running, restart it to apply the changes.
You should now have the application running locally with the ability to perform test transactions using Stripe's test cards. Follow the setup instructions carefully, and refer to Stripe's documentation for more detailed information on testing and configuring your Stripe account.
Feel free to reach out with any questions or issues you encounter while setting up the application. Happy coding!
In the project directory, you can run:
Runs both the frontend and the backend in production mode. Ensure you have built both parts of the project with npm run build-all before running this command.
Runs the backend in development mode with hot reloading and the frontend in its development mode. This is recommended for development to see immediate updates on code changes.
Installs dependencies for both the client and the server. This is a convenience script to simplify the initial setup.
Builds a production version of the application where the express server directly host the built client app running on localhost:8080
