DEV Community

Cover image for Creating a Subscription Application with Nodejs and MongoDB
Adeeyo adewale temitayo
Adeeyo adewale temitayo

Posted on • Updated on

Creating a Subscription Application with Nodejs and MongoDB

Hey There,
This tutorial will take you step-by-step through building a fully functional subscription-based platform. Along the way, you’ll learn about Express.js a web application framework for Node.js.

What we are building.
We want to build a subscription-based platform, where customers will need to subscribe to one of our plans to access our content some of our plans include Weekly, monthly plans.

This article will be broken into Modules.

1:Overview of dependencies, project setup, and server setups.

2:Authentication

3:Cron job setup

Main Dependencies

1:Nodejs must be installed

2:MongoDB database

3:Momentjs

4:node-cron

5:v-response

So guy's let get our hands dirty

Server.js file
Where we will be starting our development server,
On a successful server setup in your console, you should have
this logged.

Alt Text

Now let's create our plan model file

Alt Text

Now let's create our plan controller file

Alt Text
Alt Text

Now let's create our plan route file
Alt Text

Now we need to create our helper file for payment and calculating user next payment date

Alt Text
Alt Text

Now let's create our Signup model file
Alt Text

Now let's create our Signup controller file where we will write our logic to register a user as well as charge the user
for the payment, we will be using paystack but feel free to use any payment gateway.

Alt Text
Alt Text

So we need to configure our login to only allow subscribed users
Alt Text

At this point, we need to set up a cron job to deactivate account once the subscription ends

Alt Text

Other Features that can be added to this includes but not limited to :
Auto-renewal
Notification

And if you will like to Have this in part two of this article do let me know in the comment section

Source code

Top comments (7)

Collapse
 
bcdbuddy profile image
Babacar Cisse DIA

When you do

if (condition) {
  return something
} else { // this else is not needed
  somehtingElse
}
Enter fullscreen mode Exit fullscreen mode

You can just do

if (condition) {
  return something
}
somehtingElse
Enter fullscreen mode Exit fullscreen mode

This will help avoid deeply nested condition ie if (condition1) { if (condition2) { ...

  1. You can use markdown to put code snippets on the blog post instead of screenshots (not very clear, font is two small to read)

Nice one by the way 👍

Collapse
 
dev_tycodez profile image
Adeeyo adewale temitayo • Edited

Thanks

Collapse
 
brilliance profile image
Brilliance Oparaku

Really good read bro..Very nice I must say. thanks for the insight

Collapse
 
dev_tycodez profile image
Adeeyo adewale temitayo

Thanks man good to know it's helped

Collapse
 
nwachuk46041677 profile image
Nwachukwu Ebuka

thanks

Collapse
 
narthcodes profile image
dumtochukwu

well done! bro nice read

Collapse
 
mkhuzo profile image
mkhuzo zulu

Nice, Thanks a lot bro this one really helped me out.