Search code examples
node.jsadminlte

How to integrate apis in adminLTE in Node.js


I had successfully installed and and run admin-lte in my Node.js project. As we know they are providing us login, register and forgot password pages for ready to use.

So if I want to make an API (and that API is also made in Node.js) call on one of the page then what steps should I follow?


Solution

  • You should render html page in nodejs (for example inside express.js) and in express.js you can use template engine like: EJS - hbs ... see this Link.

    And for use API inside adminLTE you should use front end web frameworks like: reactjs - angular - vuejs or use old jquery and etc. You can even render static web page and send data into template engine via Expressjs template engine, I explained above.

    ReactJS version of the original AdminLTE dashboard: https://github.com/booleanhunter/ReactJS-AdminLTE

    AdminLte for Angular 2: https://github.com/mledour/angular-admin-lte

    See this example for load static web page with hbs:

    const express = require('express');
    const app = express();
    const port = 3000;
    //Loads the handlebars module
    const handlebars = require('express-handlebars');
    //Sets our app to use the handlebars engine
    app.set('view engine', 'handlebars');
    //Sets handlebars configurations (we will go through them later on)
    app.engine('handlebars', handlebars({
    layoutsDir: __dirname + '/views/layouts',
    }));
    app.use(express.static('public'))
    app.get('/', (req, res) => {
    //Serves the body of the page aka "main.handlebars" to the container //aka "index.handlebars"
    res.render('main', {layout : 'index'});
    });
    
    app.listen(port, () => console.log(`App listening to port ${port}`));