Wednesday, 31 May 2017

Node / Express: Communicating with main Node code from Pug template

I have a Node server doing various database requests, then it writes the page via Express and Pug (Jade) templates.

The next step is for the user to send data back via a form in the Pug template, so I need access to the Node database connection, how can I do this? I've tried linking JS files into the Pug template, but when I use:

var pg = require('pg');

.. the JS file gives an error.

Is there a way to call methods in the Node file that renders the template (index.js), from the template itself (index.pug) ?



via cal

No comments:

Post a Comment