Build SaaS Apps with Node.js The Fast Way

Gravity is a SaaS application template that saves you thousands of dollars in development time
Buy Now View Demo

The Complete SaaS Toolkit for Startups & Developers

One install complete with everything you need to build your own SaaS application

Alex Older – Web Developers Conference
“Gravity is the perfect starting point for any SaaS business and helped me get up and running quickly by taking out the hard work of building subscription payments, user authentication and designing a user interface” Alex Older - Founder, Web Developers Conference

Products Built With Gravity

Founders and freelancers use Gravity to test new ideas and build fully-loaded market-ready products

How it Works

Download and run setup – in less than two minutes, you’ll have a fully-functioning web application built with MVC and a RESTFUL API running on Express and MySQL

Code Examples

    * auth.signupAccount()
    * creates a new account + a new stripe customer
    * processes the payment and creates a new recurring monthly subscription
    * params are passed from the front-end signup form via router.js
    exports.signupAccount = async function(name, email, password, referrer, stripe_id, plan, session){
      try {
        // check if the email address is already registered with an account
        const exists = await account.doesExist(email, null);
        if (exists)
          throw ({ inputError: "email", message: "You're already registered" });
        // create a new account & stripe customer
        const customerId = await account.createStripeCustomer(email, stripe_id);
        const accountId = await account.create(email, referrer, stripe_id, plan);
        // subscribe the account to a new stipe subscription plan
        const planPrice = await account.subscribeToPlan(accountId, customerId, plan);
        // create the user and add to account
        const userId = await user.create(name, email, password, accountId, "owner");
        // set permissions and autheticate user
        session.user = userId;
        session.account = accountId;
        session.permission = "owner";
        // send welcome email
        mail.send(email, "Welcome to Gravity!", "welcome-account", { name: name, plan: plan, price: planPrice });
        // redirect user to dashboard
        return({ success: true });
    * user.invite()
    * invites a new user to join an account
    * uses invites table in the db to verify invites and remove need to
    * expose the account id in the front-end URL query
    * if a user has already been invited, the invite will be re-sent
    exports.invite = async function(email, accountId){
      try {
        // check if user has already been invited
        const sql = "SELECT account_id, invite_id FROM invites WHERE email = ? AND used = 0";
        const data = await db.query(sql, [email]);
        // user has been invited, re-send invite
        if (data.length > 0){
          const inviteURL = settings.domain + "/user/signup#" + data[0].invite_id;
          // update invite
          const sql = "UPDATE invites SET date_sent = NOW()";
          await db.query(sql);
          await sendInviteEmail(email, accountId, inviteURL);
          return true;
        else {
          // create a new invite
          const inviteID = randomstring.generate(16);
          const inviteURL = settings.domain + "/user/signup#" + inviteID;
          const sql = "INSERT INTO invites VALUES (null, ?, ?, ?, NOW(), false)";
          await db.query(sql, [inviteID, email, accountId]);
          await sendInviteEmail(email, accountId, inviteURL);
          return inviteURL;

Powered By

Stripe Logo Mailgun Logo

Get a head start on your new SaaS app today

Buy Now