The problem arose with the Jade template engine

I've been attempting to pass values into a jade template using a node/express route, but for some reason, nothing seems to be getting passed through. Below are both the server and template code snippets I am working with:

server.js:

app.get('/note/:id', function(request, response) {

    var title = notes[request.params.id]['title'];

    var message = notes[request.params.id]['message'];

    console.log(title + ' ' + message);

    response.render('note', {locals: {title: title, message: message}});

}

note.jade:

span #{locals.title}

I've also attempted to display the locals array in console, only to encounter an error.

Answer №1

It appears that passing in the locals key may not be necessary. From what I recall, it is only utilized within the template itself. You could test this out.

response.render('note', {title:title, message:message})

In your template, instead of using #{locals.title}, try using #{title}

I tested this quickly and it seems like it should be effective for you.

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

The command 'foreman' is not valid in this context

I recently began my journey with Node.js on a Windows operating system. After successfully setting everything up on my localhost, I decided to explore using heroku for hosting my application. Following the steps in this particular tutorial worked smoothl ...

Searching for nested sub documents in Node.js using Mongoose

I have a schema structure as follows: const propertiesSchema = new Schema({ name: { type: String, required: true }, shortDescription: String, totalArea: String, address: { type: mongoose.Schema.Types.ObjectId, ...

Creating a Docker container to execute Python3 from a Node.js child_process on Google App Engine

I have been working on deploying a node.js web application using a custom runtime with flex environment. In my code, I am calling child_process in Node.js to open python3 like so: const spawn = require("child_process").spawn; pythonProcess = spawn('p ...

Display a pug template when a button is clicked using Node.js and Express framework

I am struggling to grasp the concept of forms, particularly when integrating them with Express. I want my application to display a new page upon clicking a button, but I find it challenging to comprehend express routes. Any assistance would be greatly appr ...

Encountering a 404 error when using Vue history mode in conjunction with an Express

I'm facing an issue with my Vue SPA hosted on an Express server. Whenever I use history mode and refresh the page, I encounter a 404 not found exception. I attempted to solve this problem by utilizing the connect-history-api-fallback package but unfor ...

Uploading Excel data to S3 using Node.js

I've been working on a project that involves uploading an Excel file to S3 using Node.js and the aws-sdk. The input data is in JSON format, and I've been utilizing the XLSX library to convert it into a workbook before uploading it to S3 with the ...

Encountering a problem during yarn installation: '401 Unauthorized' error pops up

Every time I attempt to run yarn install, I encounter the following error: [1/5] Validating package.json... [2/5] Resolving packages... [3/5] Fetching packages... error Error: http://-----------.int:8080/tfs/-------/_packaging/Node-Packages/npm/registry/@d ...

Cannot transfer variables from asynchronous Node.js files to other Node.js files

Is there a way to export variable output to another Node.js file, even though the asynchronous nature of fs read function is causing issues? I seem to be stuck as I am only getting 'undefined' as the output. Can someone help me identify where I ...

A helpful guide on how to dynamically input database values into the href attribute of an 'a' tag

How do I successfully pass an ID to href in my code? When I try to return it via req.params, it keeps coming back as undefined. I need the ID from the URL in order to use the findOne method to access the data stored in the database. I've searched thr ...

What are the steps to connect to multiple databases with ExpressJS?

I have a server with 3 databases containing identical tables. The databases are named DB1, DB2, and DB3. When working with a specific database, I utilize the following code in app.js: var cnxDB = require('./routes/cnxDB'); app.post('/user ...

Is there a way to display a toast notification when redirecting because of an expired session with Next-Auth in a Next.js application?

Let's say I have a page named internal.tsx with the following code: export const getServerSideProps: GetServerSideProps = async (ctx) => { const session = await getSession(ctx); if (!session) { // TODO: Add a toast notification explaining t ...

Is it possible to implement transparent routing for sub applications?

It is required in Express for the sub app to have an absolute route defined. Unfortunately, using just '/' in otherApp to match all the routes from app is not a viable option. var app = express(); var otherApp = express(); app.get('/' ...

What is the most efficient way to duplicate all files from a main directory along with all its nested subdirectories using npm?

Is there a way to efficiently copy all JavaScript files from the npm directory without knowing their names in advance? The file structure looks something like this: maindir -> subdir1 -> subSubdir1 -> filea.js -> file.js -> sub ...

Loopback issue - the value cannot be identified as an object

Utilizing loopback framework on the backend and encountering a specific error: Unhandled error for request POST /api/meetups/auth: Error: Value is not an object. at errorNotAnObject (file path:80:13) at Object.validate (file path:51:14 ...

Tips for storing a buffer in an S3 Bucket

I am looking for a way to directly save a Buffer of an image into an S3 bucket without needing to save it locally. Currently, I am using the gm node module to convert an image to a buffer. This is my current code: var fs = require('fs'), ...

Leveraging the power of node.js, express, and handlebars to seamlessly render multiple views within a

I'm interested in finding out if there is a way to render multiple views using the res.render() function or another method. In the home.handlebars file, I currently have the following code: <h1>Home</h1> and I would like to display it i ...

What is the most effective approach to generating user accounts (email + password) using MongoDB and express?

As I develop my app, I'm curious about the most effective methodologies and packages that people use for creating user accounts in SaaS applications. I have been considering using Express, MongoDB, and JWT - but is this approach the best system? What ...

Having difficulty showing the custom error message from express using res.send() on the Vue side

I have a Nuxt application that utilizes Express and MySQL. Issue: I am encountering difficulty in displaying the custom error message from express res.send() on the Vue side. Let's say I want to show information for just one user. Below is my backe ...

What is the best way to utilize this resulting value as an input?

I am trying to generate a random number using math.random and use that value in the following script: let bday = Math.floor( Math.random() * (30 - 1 + 1) + 1 ); await test.page.select('select[name="day_select"]',bday); However, I am ...

Loading data using bootstrapping while the page is initializing

The following code snippets from both server.js and app.js are utilized in a guide on Lynda.com for setting up data in a web application using Backbone and Node.js. The app.get('/') request is made to the root directory, where you can observe tha ...