Build SaaS Apps with Node.js at Warp Speed

Save thousands of dollars and get your app to market before the competiton
Buy Now View Demo

The Complete SaaS Toolkit for 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 = function(name, email, password, referer, stripe_id, plan, session){
      return new Promise(function(resolve, reject){
        var accountId, planPrice;
        // check if the email address is already registered with an account
        account.doesExist(email, null).then(function(exists){
          if (!exists)
            return account.create(email, referer, stripe_id, plan);
            throw ({ status: false, error: "emailError", message: "Account already exists" });
          // create a new stripe customer
          accountId = res;
          return account.createStripeCustomer(email, stripe_id);
          // subscribe the account to a new stipe subscription plan
          return account.subscribeToPlan(accountId, customerId, plan);
          // create the user and add to account
          planPrice = price;
          return 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
          resolve({ 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 = function(email, accountId){
      // check if user has already been invited
      var sql = "SELECT account_id, invite_id FROM invites WHERE email = ? AND used = 0";
      db.query(sql, [email]).then(function(data){
        // user has been invited, re-send invite
        if (data.length > 0){
          inviteURL = settings.domain + "/user/signup#" + data[0].invite_id;
          sendInviteEmail(email, accountId, inviteURL);
          // update invite
          sql = "UPDATE invites SET date_sent = NOW()";
          db.query(sql).catch(function(err){ reject({ success: false, message: err }); });
        else {
          // create a new invite
          var inviteID = randomstring.generate(16);
          var sql = "INSERT INTO invites VALUES (null, ?, ?, ?, NOW(), false)";
          var params = [inviteID, email, accountId]
          db.query(sql, params).then(function(){
            return inviteURL = settings.domain + "/user/signup#" + inviteID;
            sendInviteEmail(email, accountId, inviteURL);
            reject({ success: false, message: err });

Powered By

Stripe Logo Mailgun Logo

Get a head start on your new SaaS app today

Buy Now