How to Integrate Stripe Payment Gateway in Node.js ?
Last Updated :
24 Mar, 2025
Integrating Stripe in Node allows one to make and manage online payments. Stripe provides developer-friendly API to set up the payment gateway to handle secure transactions.
Payment gateways help the user to make their payments. There are many payment gateways available in the market like Razorpay, Google Pay, etc but the most popular among them is the Stripe payment gateway. Stripe is the premier option for online credit card processing and it is also the most popular premium payment gateway.
- It's easy to get started and easy to use.
- It is a widely used and popular module for processing payments.
- User-friendly services and highly secured.
Approach
To integrate Stripe Payment Gateway in Node we will install the Stripe package as a project dependency. Then, we set up environment variables for authentication, and API endpoints for processing payments, and handled the transactions.
Steps to Setup Stript Payment Gateway in Node
Step 1: Initialize a Node Project
Use this command to create a node project in the same folder
npm init
Step 2: Install Stripe Module
You can visit the link Install stripe module. You can install this package by using this command.
npm install stripe
Step 3: Verify the Installation
After installing stripe module, you can check your stripe version in command prompt using the command.
npm version stripe
Step 4: Install other required modules
npm install ejs express body-parser
Project Structure:
project structureStep 5: Import Stripe
You need to include stripe module in your file by using these lines.
const stripe = require('stripe')('Your_Secret_Key');
To get your secret key, simply go to Stripe Official Website and create an account, then you can get your secret key as well as the publishable key.
HTML
<!-- Filename - Home.ejs -->
<!DOCTYPE html>
<html>
<title>Stripe Payment Demo</title>
<body>
<h3>Welcome to Payment Gateway</h3>
<form action="payment" method="POST">
<script
src="//checkout.stripe.com/v2/checkout.js"
class="stripe-button"
data-key="<%= key %>"
data-amount="2500"
data-currency="inr"
data-name="Crafty Gourav"
data-description="Handmade Art and Craft Products"
data-locale="auto" >
</script>
</form>
</body>
</html>
JavaScript
// Filename - index.js
const express = require("express");
const bodyparser = require("body-parser");
const path = require("path");
const app = express();
const Publishable_Key = "Your_Publishable_Key";
const Secret_Key = "Your_Secret_Key";
const stripe = require("stripe")(Secret_Key);
const port = process.env.PORT || 3000;
app.use(bodyparser.urlencoded({ extended: false }));
app.use(bodyparser.json());
// View Engine Setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.get("/", function (req, res) {
res.render("Home", {
key: Publishable_Key
});
});
app.post("/payment", function (req, res) {
// Moreover you can take more details from user
// like Address, Name, etc from form
stripe.customers
.create({
email: req.body.stripeEmail,
source: req.body.stripeToken,
name: "Gourav Hammad",
address: {
line1: "TC 9/4 Old MES colony",
postal_code: "452331",
city: "Indore",
state: "Madhya Pradesh",
country: "India"
}
})
.then((customer) => {
return stripe.charges.create({
amount: 2500, // Charging Rs 25
description: "Web Development Product",
currency: "INR",
customer: customer.id
});
})
.then((charge) => {
res.send("Success"); // If no error occurs
})
.catch((err) => {
res.send(err); // If some error occurs
});
});
app.listen(port, function (error) {
if (error) throw error;
console.log("Server created Successfully");
});
Steps to run the program
Run index.js file using below command
node index.js

Open browser and type this URL
http://localhost:3000/
Then you will see the Payment Gateway form as shown below

Then click on 'Pay with Card' button and then you will see the stripe payment form as shown below
Fill this form with correct credit card details and click on 'Pay' button and then if no errors occur, then the following message will be displayed
Now go to your stripe dashboard and you can see the current payment details as shown below
So this is how you can integrate Stripe payment gateway in node.js. There are other payment gateways available in the market like Razorpay, Google Pay, etc.
Similar Reads
JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
JavaScript Interview Questions and Answers JavaScript (JS) is the most popular lightweight, scripting, and interpreted programming language. JavaScript is well-known as a scripting language for web pages, mobile apps, web servers, and many other platforms. Both front-end and back-end developers need to have a strong command of JavaScript, as
15+ min read
React Tutorial React is a JavaScript Library known for front-end development (or user interface). It is popular due to its component-based architecture, Single Page Applications (SPAs), and Virtual DOM for building web applications that are fast, efficient, and scalable.Applications are built using reusable compon
8 min read
Domain Name System (DNS) DNS is a hierarchical and distributed naming system that translates domain names into IP addresses. When you type a domain name like www.geeksforgeeks.org into your browser, DNS ensures that the request reaches the correct server by resolving the domain to its corresponding IP address.Without DNS, w
8 min read
REST API Introduction REST API stands for REpresentational State Transfer API. It is a type of API (Application Programming Interface) that allows communication between different systems over the internet. REST APIs work by sending requests and receiving responses, typically in JSON format, between the client and server.
7 min read
What is DFD(Data Flow Diagram)? Data Flow Diagram is a visual representation of the flow of data within the system. It help to understand the flow of data throughout the system, from input to output, and how it gets transformed along the way. The models enable software engineers, customers, and users to work together effectively d
9 min read
NodeJS Interview Questions and Answers NodeJS is one of the most popular runtime environments, known for its efficiency, scalability, and ability to handle asynchronous operations. It is built on Chromeâs V8 JavaScript engine for executing JavaScript code outside of a browser. It is extensively used by top companies such as LinkedIn, Net
15+ min read
HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML
14 min read