loading...
Cover image for Creating a Subscription Application with Nodejs and MongoDB

Creating a Subscription Application with Nodejs and MongoDB

dev_tycodez profile image Adeeyo adewale temitayo Updated on ・2 min read

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

Posted on by:

dev_tycodez profile

Adeeyo adewale temitayo

@dev_tycodez

Hi there, I'm Adeeyo Adewale Temitayo I'm a backend developer, Technical writer I currently work with intelligence campaign hub as a backend developer. I'm passionate about web development

Discussion

markdown guide
 

When you do

if (condition) {
  return something
} else { // this else is not needed
  somehtingElse
}

You can just do

if (condition) {
  return something
}
somehtingElse

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 👍