Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6764081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:33:08+00:00 2026-05-26T14:33:08+00:00

I am building a small app primarily with socket io, however with a few

  • 0

I am building a small app primarily with socket io, however with a few things from expressjs.

One function of the socket io piece is to send an email when a certain event occurs. I’ve got this working fine with node_mailer.

The problem I’m running into is that I want to use the express view engine to render the emails from template files. The render method seems to be explicitly attached to the res object prototype.

What I’ve done feels pretty dirty:

// setup express server
var render;
app.get('/', function (req, res) {
    if (typeof render == 'undefined') render = res.render;
    res.end('Welcome to app');
});

// socket io code
socket.on('event', function (data) {
    var email_content;
    render('template', {}, function (err, result) { email_content = result; });
});

Is there a better way to gain access to expressjs’s components outside the context of an http request, or even a better way to approach this problem? I tried rigging up a call to the exported express.view.compile function but that both didn’t work and seemed like a high hoo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:33:08+00:00Added an answer on May 26, 2026 at 2:33 pm

    Here is where the information you seek comes from:

    https://github.com/Ravelsoft/node-jinjs/wiki

    With templates as modules
    To have node load your templates as if they were modules, you first have to register your module extension :

    require("jinjs").registerExtension(".tpl");
    

    If you want your file to be transformed prior to being submitted to jinjs, you can pass a callback ;

    var pwilang = require("pwilang");
    require("jinjs").registerExtension(".pwx", function (txt) { 
        return pwilang.parse(txt); 
    });
    

    You can now write this to user Jin:

    var my_template = require("./mytemplate");
    var context = { foo: "foo", bar: "bar" };
    var result = my_template.render(context);
    

    Because you are sticking Jin into express (as opposed to making express work with Jin) this is your best option. The res variable is only available in the route callback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a small app to send my 2do list stuff to Evernote over
I'm building a small app that calculate hash from any given file to multiple
Right now I'm building a small app that imports data from a spreadsheet and
I am building a small app in Lazarus and need a parse function based
I'm building a small app where a user will input a date from 3
I am building a small wpf app in C#. When a button gets clicked
I'm building a small web app in PHP that stores some information in a
I am building a small rails app and I need a way to generate
I am building a small facebook app. Trying to search for values in an
I have a relatively small app that Im building using vb.net 2.0, and nant.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.