Getting started

Learn about how FasterNode works, how to set up the project, its main features, and how you can use it to ship your SaaS or web app faster.

Introduction

FasterNode is the all-in-one solution for building SaaS businesses quickly. Get a pre-built foundation with user authentication, payment integration, email notifications, and more - all with clean, modern code.

Get a Node.js starter template with everything you need, including:

  • Seamless User Authentication: Secure login and account management for your users.
  • Frictionless Payments: Integrate Stripe for easy payment processing.
  • Automated Emails: Send automated emails for signup, transactions, and more.
  • Clean and Maintainable Code: Well-written codebase for a smooth development experience.

This documentation covers the following topics and more:

Installing dependencies

This part of the set up tutorial assumes that you already have Node.js and NPM installed on your system. If you don't have Node.js installed, you'll have to install it. The method of installation will depend on your operating system, there are numerous online tutorials on how to do so.

Once you have downloaded the FasterNode repo you will need to install dependencies and all the necessary packages. This can be achieved with a single command.

Start by unzipping the FasterNode.zip file in your desired location. Once unzipped, open up a new terminal window and navigate to the FasterNode repo.


Run the following command:

npm install

All the necessary dependencies should now be installed.

Set up the MySql database

The following section assumes you already have MySql installed on your system and that a MySql user has already been added. If you do not have MySql installed, you should install it before you proceed with the following steps. The installation method depends on your operating system, however there are many great online tutorial that will guide you through the process of installing MySql.


Open up a new terminal window and navigate to the FasterNode directory.

Run the follwing command (where you replace "username" with either "root" or your actual MySql username):

mysql -u username -p

Enter your MySql password when prompted.

Once you are logged in MySql run the following command to create a database named fasternodeDB

CREATE DATABASE fasternodeDB;

Once the new database is created you can run the following command to exit MySql:

exit

You should now be logged out of MySql.

It is now time to restore the database from the MySql dump file. This file is located in the FasterNode directory.

In the same terminal window as before, run the following command (replacing username with root or your actual MySql usename:

mysql -u username -p fasternodeDB < fasternodeDB.sql

Enter your MySql password when prompted.


The database should now be restored successfully.

It is now time to make changes to the .env file located in your main FasterNode directory. Open up the .env file in your favorite code editor.

Change the values after the = sign in the first two lines. The value for the first line is your MySql password, and the value of the second line is your MySql username.

Save and close the .env file.


That's it, you have now successfully set up the MySql database for your FasterNode project.

Set up Stripe for subscriptions

In this section we'll go through the process of setting up Stripe for recurring subscriptions payments.

If you do not already have a Stripe account, you should go ahead and signup for one. You should also retrieve your development test api key. Keep a hold of your api key as you will need it later.

Install the Stripe CLI. The CLI provides webhook testing, and you can run it to create your products and prices. Run the following command to install the Stripe CLI:

# Install Homebrew to run this command: https://brew.sh/
brew install stripe/stripe-cli/stripe

Run the following command and follow the instructions to connect to your Stripe account via the CLI.

stripe login

Open up a new terminal window and type the following command:

stripe listen --forward-to localhost:3200/webhook

This should output a webhook signing secret, keep a hold of it as we will need it in the next step.

It is now time to make changes to the .env file. open up the .env file in your favorite code editor. Replace the two values after the = sign as higlighted in the image below.

The first value is STRIPE_API_KEY, this is your Stripe test API key.

The second value is STRIPE_WEB_HOOK_SECRET, this is the webhook signing secret we retrieved in the previous step.

Once you have replaced both values, save your file.


It is now time to create a new subscription so you can start accepting recurring payments. Later in this guide we will have a look at how to set up one-time payments as well.

To create a new subscription, head over to your Stripe dashboard and click on the Test Mode toggle button.

next click on ... More

Click on Product catalogue

By default FasterNode comes with three different subscriptions tiers, The first tier is free and does not require a Stripe subscription nor does it require a credit card to sign up for, so we only need to create two payed subsciption products. We will be adding two payed subscriptions to the project, the first subscription we will create should be the less expensive of the two. To add a new product, click on Add product

Fill in the required information, like the product name and description. Make sure to set the payment as recurring by selecting the Recurring option like in the image below. Set your price, currency, and the billing period to monthly (or any other billing period option available).

Once you are done click on Add product. The product should now appear on your Product catalogue screen.

Click on the product you've just created to expand display the product details.

Copy the product API ID, as shown in the image below.

It is now time to add the API ID we just copied to our code. We will need to do so in a couple of files. First Open up the server.js file located in your main FasterNode repo.

We will modify an object named sub_object, it is located on line 48 of the server.js file.

Replace the first key with the API ID of the product you just created.

Save your file.

Now open up the pricing.html page located in the /public directory. Scroll down to line 113 and replace the value of the input with id priceId_1 as shown in the image below. Once you're done remember to save your file.

Congratulations you've just added your first subscription. Now let's do the same for the most expensive tier subscription.

Just repeat the same steps as above to cretate a new product only this time make sure to set the price higher than the first subscription product.

Click on the newly created product to display the details, copy the API ID for your second tier product and head back to the server.js file, replace the second key in the sub_object object as shown below.

Now head back to the pricing.html page located in the /public directory. Scroll down to line 120 and replace the value of the input with id priceId_2 as shown in the image below. Once you're done remember to save your file.

If subscriptions are the only payment method you want to set up, then you are now done with the Stripe set up process. You can move on to the next setp of the FasterNode set up process. However if you want to set up a One-time payment model as well, you should keep reading.

Set up Stripe for one-time payments

In this section we'll go through the process of setting up Stripe for recurring subscriptions payments.

If you do not already have a Stripe account, you should go ahead and signup for one. You should also retrieve your development test api key. Keep a hold of your api key as you will need it later.

Install the Stripe CLI. The CLI provides webhook testing, and you can run it to create your products and prices. Run the following command to install the Stripe CLI:

# Install Homebrew to run this command: https://brew.sh/
brew install stripe/stripe-cli/stripe

Run the following command and follow the instructions to connect to your Stripe account via the CLI.

stripe login

Open up a new terminal window and type the following command:

stripe listen --forward-to localhost:3200/webhook

This should output a webhook signing secret, keep a hold of it as we will need it in the next step.

It is now time to make changes to the .env file. open up the .env file in your favorite code editor. Replace the two values after the = sign as higlighted in the image below.

The first value is STRIPE_API_KEY, this is your Stripe test API key.

The second value is STRIPE_WEB_HOOK_SECRET, this is the webhook signing secret we retrieved in the previous step.

Once you have replaced both values, save your file.


It is now time to create a new subscription so you can start accepting recurring payments. Later in this guide we will have a look at how to set up one-time payments as well.

To create a new subscription, head over to your Stripe dashboard and click on the Test Mode toggle button.

next click on ... More

Click on Product catalogue

By default FasterNode comes with a single One-off product. To create a one-off payment product click on Add product

Fill in the required information, like the product name and description. Make sure to set the payment as One-off by selecting the One-off option like in the image below. Set your price and currency.

Once you are done click on Add product. The product should now appear on your Product catalogue screen.

Click on the product you've just created to expand display the product details.

Copy the product API ID, as shown in the image below.

It is now time to add the API ID we just copied to our code. We will need to do so in a couple of files. First Open up the pricing_single.html file located in the /public directory of your FasterNode project.

Scroll down to line 89 and replace the value of the input element with id of priceId and save your file.

Now open up the index.html file located in the /public directory. Scroll down to line 510 and replace the value of the input element with id of priceId and save your file.

If one-off payments are the only payment method you want to set up, then you are now done with the Stripe set up process. You can move on to the next setp of the FasterNode set up process. However if you want to set up a recurring subscription payment model as well, you should refer to the previous section.

Set up Mailgun for emails

In this section we will go through the process of setting up Mailgun for emails. It is assumed that you already have a mailgun account. If you don't have a mailgun account you should go head over to the mailgun website and create one.

You will need to choose a Mailgun subscription when you first create an account, you do however get a 1 month free trial. I recomment getting the 50K emails subsription to begin with.

Mailgun subsriptions are great because you can link, and send from multiple domains with a single paid subscription. So you can stretch the subsciption and use the service accross multiple apps.

Once you have created and signed in to your account, head over to your mailgun dashboard, click on the Switch region button and select your region as shown in the image below.

Next click on Sending in the left hand side panel.

Next click on the Add new domain button.

Enter your domain name and click on Add domain.

On the next screen you'll need to follow the required steps to verify your domain. Once you have taken all the necessary steps and added the required records to your DNS click on the Verify DNS settings button.

If done correctly, the status of each DNS record should turn green and display the word verified as shown in the image below. If it is not the case try to wait for a couple of minutes and reload the page.

Next, click on your username in the top right corner of the screen to reveal a dropdown menu, and select IP Access Management like shown in the image below.

On the new screen, click on the Add IP addresses button. Add your IP address to the list of authorized Ip addresses and save.

Next head back to your dashboard and click on API Keys like shown in the image below.

Next click on Add new key.

Copy your API key and make sure to save it somwhere safe, as we will be using it shortly.

The API key is only displayed once, so make sure to save it somewhere for later use.

Now it is time to make some changes to our .env file again. open up the .env file in your favorite code editor. Replace the values after the = sign as shown in the image below. the first value to replace is MAILGUN_API_KEY (paste the API key you just copied from the Mailgun dashboard), and the second value is DOMAIN (here goes the domain name you've registered with Mailgun).

There is one last thing you need to set up before you are done with Mailgun, and that is email forwarding. You need a way to receive emails so for that you will forward all emails sent to your domain name to an email address that you own. This way you will always receive emails sent to your domain even if an email address does not exist.

If you want to know more and get familiar with email forwarding using Mailgun, click here.


To set up email forwarding, head over to your Mailgun dashboard and click on Receiving in the left hand side menu.

Next click on Create route

On the next screen set the Expression Type as Catch All, activate the the Forward toggle button

, and insert the email address where you want to receive the inbound emails.

Leave all other values as is and scroll down to the bottom of the page. Click on the Create route button.

Next click on Save.

That's it, you have now successfully set up Mailgun for both outbound and inbound emails.

Set up Google OAuth for seamless auth

It is assumed that you already have a Google Gmail account, as you will need one to set up Google OAuth. If you don't already have a Gmail account, you should go ahead and create one to proceed with this guide.


The first step in implementing OAuth 2.0 is obtaining credentials for the client i.e. Client ID and Secrets.

To get started head over to the Google Cloud Console.

Fill in the Project Name and click on theCREATE button.

Next expand the left hand side panel and click on APIs and services.

Next click on Credentials.

On the next screen click on the CREATE CREDENTIALS button.

From the dropdown menu select OAuth client ID.

If prompted on the next screen, click on CONFIGURE CONSENT SCREEN.

Set the User Type to External, and click on theCREATE button.

On the next screen scroll down and insert you email address in the Developer contact information section, then click on the SAVE AND CONTINUE button.

On the next screen click on ADD OR REMOVE SCOPES.

From the pop-up screen, select the top 3 options as highlighted in the image below.

Scroll down and click on UPDATE.

Once the pop-up screen closes, scroll down and click on SAVE AND CONTINUE.

On the next screen, click on ADD USERS.

Add your Gmail email address as a user, then click on SAVE AND CONTINUE.

On the next screen set the Application type to Web application.

Set the Authorised JavaScript originurl to http://localhost:3200 and set the Authorised redirect URIs field to http://localhost:3200/auth/google/callback then click on CREATE.

Congratulations, you have now created a new OAuth client. You can now copy your Client ID and Client secret somwhere safe as they are needed in the next step.

Head back to your .env file and change the values after the = sign for: GOOGLE_CLIENT_IDwith the Client ID you just copied from the Google cloud console, and GOOGLE_CLIENT_SECRET with the Client Secret you also copied from the Google cloud console.

Save your .env file.

That's it, you are now done with the Google OAuth 2.0 set up. You can now proceed to the final step of the FasterNode set up process. You are 2 minutes away from starting your new App.

Set up your Admin password

FasterNode ships with an Admin Dashboard. The admin dashboard allows you to perform the following operations.

  • Get a user account details.
  • Get a user messages.
  • Get a user support tickets.
  • Get all unanswered messages.
  • Send support emails to users.

In order to perform tasks from the admin dashboard you'll need to insert your admin password. To set the admin password, open up the .env file located in your main FasterNode repo, and update the value for ADMIN_PASSWORD like shown in the image below.

FasterNode Helper Functions

FasterNode provides a solid foundation for your next project. It includes essential functionalities to streamline your development process and improve code organization.


A key feature of this boilerplate is the inclusion of helper functions. These pre-written functions encapsulate common tasks and utilities, saving you time and effort while promoting code reusability and maintainability.

By utilizing these pre-built functions, you can focus on the core logic of your application without reinventing the wheel for everyday operations.

The following sections will guide you through the structure of the boilerplate and demonstrate how to leverage the included helper functions for a productive development experience.


By default FaterNode ships with the following helper functions:

is_user_logged_in(email, user_access_key)

The function is named is_user_logged_in.

As it name implies, the function is used to check whether a user is logged in or not.

It takes two arguments: email (string) and user_access_key (also a string).

The function returns a new Promise. This allows asynchronous handling of the database operation.

Basic usage would look something like this:

const is_logged_in = await is_user_logged_in(email, user_access_key);

The function returns a bool value, true if the user is logged in, and false if not logged in.

Below is an example get route that makes use of the is_user_logged_in helper function.

app.get('/download', async function(req, res){
    const email = req.query.email;
    const user_access_key = req.query.user_access_key;

    const is_logged_in = await is_user_logged_in(email, user_access_key);

    if(is_logged_in === true){
        const file = `${__dirname}/downloads/test_file.zip`;
        res.download(file);
    }else{
        res.status(400).send({message: 'bad request'});
    }
});
is_user_premium(email, user_access_key)

The function is named is_user_premium.

As its name implies, the function is used to check whether a user has a premium or not (has a paid subscription or have paid for access to your product with one-off payment). This is particularly useful for private/protected routes and API calls.

It takes two arguments: email (string) and user_access_key (also a string).

The function returns a new Promise. This allows asynchronous handling of the database operation.

Basic usage would look something like this:

const is_premium = await is_user_premium(email, user_access_key);

The function returns a bool value, true if the user is premium, and false if the user is not premium.

Below is an example get route that makes use of the is_user_premium helper function.

app.get('/download', async function(req, res){
    const email = req.query.email;
    const user_access_key = req.query.user_access_key;

    const is_premium = await is_user_premium(email, user_access_key);

    if(is_premium === true){
        const file = `${__dirname}/downloads/test_file.zip`;
        res.download(file);
    }else{
        res.status(400).send({message: 'bad request'});
    }
});
get_user_subscription(email)

The function is named get_user_subscription.

As its name implies, the function is used to retrieve the user subscription.

It takes one argument: email (string).

The function returns a new Promise. This allows asynchronous handling of the database operation.

Basic usage would look something like this:

const user_subscription = await get_user_subscription(email);

The function returns an int value, 0 if the user has no paid plan, 1 if the user has a first tier subscription, and 2 if the user has a second tier subscription.

Below is an example get route that makes use of the get_user_subscription helper function.

app.get('/download', async function(req, res){
    const email = req.query.email;
    const user_access_key = req.query.user_access_key;

    const user_subscription = await get_user_subscription(email, user_access_key);
    console.log(user_subscription)

    if(user_subscription > 0){
        const file = `${__dirname}/downloads/test_file.zip`;
        res.download(file);
    }else{
        res.status(400).send({message: 'bad request'});
    }
});
does_user_exist(email)

The function is named does_user_exist.

As its name implies, the function is used to check if a user exists or not.

It takes one argument: email (string).

The function returns a new Promise. This allows asynchronous handling of the database operation.

Basic usage would look something like this:

const user_exists = await does_user_exist(email);

The function returns a bool value, true if the user exists, and false if the user does not exist.

Below is an example get route that makes use of the does_user_exist helper function.

app.get('/download', async function(req, res){
    const email = req.query.email;
    const user_access_key = req.query.user_access_key;

    const user_exists = await does_user_exist(email, user_access_key);
    console.log(user_exists)
    
    if(user_exists === true){
        const file = `${__dirname}/downloads/test_file.zip`;
        res.download(file);
    }else{
        res.status(400).send({message: 'bad request'});
    }
});
validate_email(email)

The function is named validate_email.

As its name implies, the function is used to check if a email address is valid or not.

It takes one argument: email (string).

Basic usage would look something like this:

const is_email_valid = await validate_email(email);

The function returns a bool value, true if the email is valid, and false if the email is not valid.

validate_password(password)

The function is named validate_password.

As its name implies, the function is used to check if a password is valid or not. (longer than 8 characters, includes upper and lower case letters, includes at leat one number and a special character).

It takes one argument: password (string).

Basic usage would look something like this:

const is_password_valid = await validate_password(password);

The function returns a bool value, true if the password is valid, and false if the password is not valid.

CSS Styles

Learn how to customize the primary brand color for you FasterNode application.

Change brand color across the entire app

Changing your brand primary color is very easy. You'll only need to change a few css variables in the main.css file located in the /public/css/ directory of your FasterNode application folder. It is recommended that you user rgba colors.

Open up the main.css file in your favorite code editor, you'll need to change the rgba values for the css variables on line 15 and line 16.

  • --dark-primary-color, this is the primary color used across your entire FasterNode application.
  • --dark-primary-color-alt, this is the accent color used when hovering over buttons and other elements.
--dark-primary-color: rgba(129, 217, 95, 1);
--dark-primary-color-alt: rgba(129, 217, 95, .9);

Next you'll need to scroll down to line 57 of the main.css file and change the values for the following css variables:

  • --primary-color, this is again the primary color used across your entire FasterNode application.
  • --primary-color-alt, this is again the accent color used when hovering over buttons and other elements.
--primary-color: rgba(129, 217, 95, 1);
--primary-color-alt: rgba(129, 217, 95, .9);

Save the main.css file.

That's it! You have successfully changed the primary color for your entire FasterNode application.

Start the Tailwind CLI build process

Tailwind CSS comes already installed and pre-configured in FasterNode, you can start using Tailwind styled components out of the box.

All you need to do, is run the CLI tool to scan your template files for classes and build your CSS.

To do so, open up a new terminal window, navigate to your FasterNode repo and run the following command:

npx tailwindcss -i ./src/styles.css -o ./public/css/output.css --watch

The command above will create a file called output.css in the /public/css folder. This file will contain all the necessary Tailwind styles for your project.

You should also link the following stylesheet to the html file where you want to use the Tailwind styles:

<link rel="stylesheet" type="text/css" href="css/output.css">

If you want to find out more about Tailwind CSS and how it is used please check This link.

Usage

To start your FasterNode app, open up a new terminal window, navigate to the app directory and run the following command:

node server.js

This will start your app on port 3200

You should see the following output in your terminal window:

yourdomain.com
Listening on port 3200
Connected to mysql

Open up your favorite browser and visit http://localhost:3200/

Congratulations, your FasterNode app is now running.

Before you start your FasterNode app

Make sure to follow this documentation and properly install the different dependencies. You should configure mysql, stripe and mailgun at the very least, for your FasterNode app to be functional. It is recommended that you also set up Google OAuth.