Most Popular Tutorials




What is Render in node.js?

Render

The app.render() method is used for returning the rendered HTML of a view using the callback function. The res.render() function is used to render a view and sends the rendered HTML string to the client. This method accepts an optional parameter that is an object which contains the local variables for the view.

  • Locals: It is basically an object whose properties define local variables for the view.
  • Callback It is a callback function.
  • res.render(view [, locals] [, callback])

    File Name :

    app.get('/ittutorial', function(req, res){
    // Rendering ittutorial_home.ejs page
    res.render('ittutorial_home');
    })

    // here ittutorial_home is the view page.

    File Name :

    res.render('home');

    ############### Or #########

    res.render('home', function(err, html) {
    if(err) {...}
    res.send(html);
    });

    File Name : home.ejs

    <html>
    <head>
    <title>res.render() Demo</title>
    </head>
    <body>
    <h2>Welcome to Coding Ninjas</h2>
    </body>
    </html>





    Previous Next


    Trending Tutorials




    Review & Rating

    0.0 / 5

    0 Review

    5
    (0)

    4
    (0)

    3
    (0)

    2
    (0)

    1
    (0)

    Write Review Here


    Ittutorial