Grandjs A Promising Nodejs framework
Tags: node, grandjs, newframeworks, javascript
Published: 2019-12-06 17:29:13

---
title: Grandjs A Promising Nodejs framework
published: true
description: A nodejs Article about Grandjs a new nodejs framework
tags: nodejs, grandjs, new frameworks, javascript
cover_image: https://thepracticaldev.s3.amazonaws.com/i/ad898svf0i4hhtrtwoaq.jpg
---

Since Nodejs has launched to the developers world, it gained large community shortly and in short time nodejs became one of the most backend programming environment to build scalable web apps using javascript programming language. One of the most important factors that made nodejs in the title of web development is the community and the large amount frameworks, libraries and packages that made upon top of nodejs to help you develop more easier and fast.
Today we are talking about [Grandjs](https://github.com/tareksalem/grandjs) framework which is a new framework built upon nodejs and javascript to allow you build strong and efficient web app easily.

## What is Grandjs ?
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/5o5oy1ycvzaf9enyo6k8.png)

Grandjs is a new framework, built on top of nodejs, it contains some of built in packages, libraries, helpers to allow you build your web app easily without using many packages and libraries to fit out your expectation, Grandjs offers many of helpers such as validations, file uploader, auth system, sessions and many other features to  build your web apps easily.
one of the amazing things in Grandjs that it allows you to write your routes easily using object oriented programming, yes Grandjs routes are built upon javascript oop and allows you to consume the router class using oop to build extendable routing system.

## What are the benefits that Grandjs offers ?
Yes as you a developer, maybe you are working fin currently with other frameworks such as express, sails, hapijs, loopback and so on, so you may ask yourself why should I take a lock and use grandjs, what is the new things in grandjs that offers ?
so here are some points about grandjs:
1- as we mentioned above, grandjs gives you an extendable routing system that helps you build your routes based on javascript oop which makes you encapsulate every group of routes in a class, also you can make error page for fault routes for every router class you build, in the addition you can easily include sub classes of routes inside main router, all of these benefits gives you an obvious code and file structure you can follow to build your MVC scalable web app without the confusion that happens when you develop with framework like expressjs.

Here is the example of building routes in Grandjs:
```javascript
const Grandjs = require("grandjs");
const ProductController = require("../controllers/product.controller");
//extend the router class
class AdminRoutes extends Grandjs.Router {
    constructor(options) {
       super(options);
       this.getRouters = [this.showProducts()];
    }
    // set error page for not found pages
    errorPage(req, res) {
            return res.status(404).json({ status: 404, message: "not found" });
    }
    // show products for admin
    showProducts() {
            return {
                url: "/products",
                method: "GET",
                handler: (req, res) => {
                    ProductController.showProducts(req.query)
                        .then(data => {
                            return res.status(data.status).json(data);
                        })
                        .catch(err => {
                            return res.status(err.status).json(err);
                        });
                }
            };
    }
}
const AdminRouter = new AdminRoutes({ base: "/admin" });
```

if you can see in the above example, the we extended router class to admin routes which includes one router which is showProducts method which list the products to admin, we call the controller from another file, also we defined error page for this router class easily, and finally we instantiate the router with base url  ``/admin``

2- Another amazing thing in Grandjs that it gives you built in validation class which is used for any validation you want to apply on any data type such as strings, objects, numbers, and custom type such as images and so on.

3- Grandjs uses handlebars as a template engine if you want to render html content and make data binding from backend
4- Grandjs includes Auth module for sessions and logins
5- Grandjs includes built in Cryption module to encrypt your data and hash them
6- one of the most important things that Grand includes is the flash messages system that helps you to send readable messages to the template engine to view them to the client
7- Another thing that Grandjs offers is a method to add custom Mimetypes to the file mime types recognition in grandjs

### What is new in Grandjs
Grandjs now has added built in File uploading module to upload files easily.

### What do you need to start in grandjs ?

you don't need anything to start with grandjs just basic knowledge in javascript and nodejs

you can find the documentation of grandjs and detailed examples on github and NPM.

Grandjs on github: https://github.com/tareksalem/grandjs

Grandjs on npm: https://www.npmjs.com/package/grandjs