Socket
Socket
Sign inDemoInstall

consolidate

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consolidate

Template engine consolidation library


Version published
Weekly downloads
1.9M
increased by1.28%
Maintainers
1
Weekly downloads
 
Created

What is consolidate?

The consolidate npm package is a template engine consolidation library for Node.js. It allows developers to use various template engines with a unified API, making it easier to switch between them or support multiple engines in a project.

What are consolidate's main functionalities?

Template Engine Agnostic

Consolidate.js works with many template engines, allowing you to define the engine you want to use for rendering your views. In this example, Swig is used as the template engine for an Express app.

const cons = require('consolidate');
const express = require('express');
const app = express();

app.engine('html', cons.swig);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');

app.get('/', function (req, res) {
  res.render('index', { title: 'Consolidate.js' });
});

Asynchronous Template Rendering

Consolidate.js supports asynchronous rendering of templates. Here, Mustache is used to render a template file asynchronously, and the result is logged to the console.

const cons = require('consolidate');

cons.mustache('views/index.mustache', { title: 'Consolidate.js' }, function(err, html){
  if (err) throw err;
  console.log(html);
});

Caching Templates

Consolidate.js allows you to enable caching for template engines that support it, which can improve performance. In this example, Dust's caching feature is enabled.

const cons = require('consolidate');
const app = require('express')();

app.engine('dust', cons.dust);

cons.requires.dust.cache = true;

app.set('view engine', 'dust');
app.set('views', __dirname + '/views');

// ... rest of your app

Other packages similar to consolidate

Keywords

FAQs

Package last updated on 04 Jan 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc