Leveraging Dust.js LinkedIn templates within a Node.js framework alongside Express 3.x

I am struggling to understand how to implement the dustjs-linkedin templates in express 3.x

 #app.js
  var dust = require('dustjs-linkedin');

  app.set('view engine', 'dust');

  app.get('/test1', routes.test1);

#./routes/test.js
exports.test1 = function(req, res){
  res.locals.session = req.session;
  res.render('test1', { title: 'Test 1' } );
};

#./views/test1.dust
{+base.dust/}
{<main}
  Child Content
{/main}

#./views/base.dust
    {+main}
      Base Content
    {/main}

Upon navigating to /test1, I encounter the following error:

500 Error: Cannot find module 'dust'

Answer №1

I encountered similar issues and found a solution to streamline the integration of dustjs-linkedin with express 3.x by creating a convenient library called klei-dust. This library is easy to configure and allows you to specify the root folder for views, including base templates and partials.

For example, if you have a views directory located at views/ containing templates named home.dust and base.dust, your home.dust template could look like this:

{>base/}
{<main}
Hello world
{/main}

This eliminates the need to create a separate views/base.dust file in order for it to function correctly.

Answer №2

After some trial and error, I successfully integrated dustjs-linkedin with consolidate module.

Explore the implementation here

It's worth noting that the layout must be wrapped in double quotes, a detail that caused me some initial confusion. Also, it is relative to the app.js file and requires a trailing /

{+"views/base.dust"/}
<p>Page content here</p>

Answer №3

If you're looking to integrate express 3.x with dustjs-linkedin, I can provide some guidance.

First off, express requires two configurations: 'view engine' and app.engine.

The 'view engine' simply sets the default engine, while app.engine maps an engine to a specific file extension.

To set this up, try something like:

app.set('view engine', 'dustjs-linkedin');
app.set('views', __dirname + '/views');
app.engine('dust', dust.compileFromPath);

One issue with this approach is that the compileFromPath method is not present in dust.

You'll need to add a method to the dust object with the signature Express expects: (path, options, callback).

For more information on this, check out http://expressjs.com/api.html#app.engine.

Alternatively, you could consider using consolidate (), but keep in mind that it doesn't support the dustjs-linkedin version, only the older dust version.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Launching web application and worker on Heroku directly from GitHub

So I have this web application where I've successfully implemented continuous deployment from Github. However, my next step is to introduce some worker roles to the app and I have a few questions regarding this. The app is built using Node.js. I envi ...

Having trouble locating the web element within a div popup while utilizing Node.js and WebdriverIO

I need assistance with a seemingly simple task. I am currently learning webdriverjs and attempted to write a short code to register for an account on the FitBit website at URL: www.fitbit.com/signup. After entering my email and password, a popup appears as ...

Encountering a Node.js issue with http.get while trying to retrieve an RSS feed using node-webkit, specifically the error message

Currently, I am developing an RSS aggregator using node-webkit. However, I have encountered an issue where a certain number of my requests (code provided below) are failing with various errors such as HPE_INVALID_CONSTANT, ETIMEDOUT, EAGAIN, and HPE_INVALI ...

Child_process module spawn method in Node.js

When I attempt to play an audio stream using the mpg123 command, everything works perfectly fine. I have also implemented a method to terminate the process successfully. However, I am struggling to retrieve output from the executed command. Despite follow ...

Capture a snapshot of a webpage that includes an embedded iframe

Currently, we have a nodeJS/angular 4 website that contains an iframe from a third party (powerBI Emebdded). Our goal is to develop a feature that allows the end user to capture a screenshot of the entire page, including the content within the iframe. We ...

Building and saving an HTML webpage using Node.js: A step-by-step guide

Using node.js, I developed an application that gathers data in a MongoDB database. For example: name: John pagename: mypage links: [link1, link2, link3] The task at hand is to generate static HTML pages with the format pagename.mydomainname.com, and ins ...

Ember.js: Loading and Playing Audio Files

I've been working on an ember-app that will need to load an audio file during some point in the development process. As I'm also creating a REST-Server using express.js simultaneously, I am trying to figure out the best way to provide the mp3-fil ...

How to Change a Property in a Child DTO Class in NestJS with Node.js

I am working with enums for status: export enum Status { Active = "Active", Inactive = "Inactive", } Additionally, I have a UserStatus enum: export enum UserStatus { Active = Status.Active, }; There is also a common dto that inc ...

Capturing every unaddressed error in Gulp

One common issue we encounter with new developers is our Gulp build process failing, producing the following error message: events.js:85 throw er; // Unhandled 'error' event ^ Error: EMFILE, open '[some filename]' ...

What could be the reason behind the login button not triggering the console message display?

I've decided to delve into web server development on my own and have been tweaking a GitHub repository for ExpressJS with Typescript that I stumbled upon. My initial goal is simple - just to have something displayed on the console when I click the log ...

Why MongoDB's Push Operation Using Positional Operator isn't Functioning

In the 'users' collection, I have a document with the following data: { "_id" : "388179687996974", "matches" : [ { "userId" : "1495728740672094", "choice" : false, "dates" : [], "d ...

Sending a cURL POST request to a Node.js express server running on an NGINX server resulted in a 502 error response

I am attempting to send a POST request to one of my node API routes. Strangely, only one of them seems to be working properly. I'm not certain whether this is an issue with NGINX, Node.js, or a combination of both. I have double-checked everything and ...

Combine mongoose $sum aggregations

I am facing a query that looks like the following: {"$match": {$or: [{"to": system.mongoose.Types.ObjectId(userId)}, {"from": system.mongoose.Types.ObjectId(userId)}]}}, {"$sort": {"createDate": -1}}, { "$group": { ...

What is the best way to save files on a web hosting platform?

Hey everyone, I hope you're all having a good evening. Recently, I developed a React Application that allows users to upload and store images both locally and on MongoDB along with some additional data. During local development, everything was working ...

How does npm determine which packages are considered direct dependencies when using the 'npm list' command

Upon entering the following three commands, a new directory is created: npm install underscore npm install lodash npm install express The result is a node_modules folder containing numerous packages: $ ls node_modules accepts cookie-signat ...

Encountering a 400 error in Ajax following the execution of server-side validation by Express

I'm currently troubleshooting a form handler that consistently throws a 400 error post middleware validation. The middleware validation steps are as follows: const contactValidate = [ check('name') .exists() .trim() .escape() ...

Having trouble linking tables to Node.js with TypeScriptyntax?

I am facing an issue with mapping multiple entities using sequelize. I keep encountering the error message " Error: Profesor.hasOne called with something that's not a subclass of Sequelize.Model". How can I resolve this issue? Below is the code for t ...

Slightly puzzled by the declaration of `var app = express()`

After going over the documentation, I'm still struggling to grasp why we store express() inside an app variable. I attempted to call methods using express().get and .post directly, but was unsuccessful. Why is that? Why doesn't it function in t ...

Nodemailer fails to send out emails despite the absence of any error messages

I'm currently working on setting up a confirmation email feature for user sign-ups on my website. I've tackled similar tasks in the past, but this time I've hit a roadblock - the emails are not being sent, and there are no error messages to ...

Achieving enlightenment with Satori in NextJS: Transforming SVG to PNG in a NodeJS Environment

I am currently exploring the capabilities of satori and integrating it into my next.js api routes. (I'm unable to utilize the vercel/og package). While I have successfully set everything up, I'm facing a challenge in converting the svg image gen ...