Build SaaS Apps with Node.js The Fast Way

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

108 Startups & Developers Trust Gravity

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

Need a feature that we haven’t listed?

We can customise Gravity to include additional features that fit your project requirements.

Customise Gravity

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

Download Now