I am working together with a friend on developing a modification for my ghost website. We have hit a bit of a wall in our knowledge and wanted to ask the community for help.
Here is what we want to achieve:
- Our Ghost install is hosted on a Digital Ocean droplet using Nginx on an Ubuntu server with Node.js and MySQL included (as detailed here).
- We would like to use Node.js to connect to the MySQL server to retrieve data from within a handlebars template.
How do we achieve this?
“I’m able to ‘npm install mysql’ in the terminal and register it in the theme’s package.json file, but once inside of the tag inside of the .hbs template, ‘var mysql = require(‘mysql’)’ doesn’t work, mysql returns as ‘undefined’. I’ve tried requiring it in a .js file, and importing then importing that .js file in the .hbs template, but no luck there either.”
How do we connect to, and retrieve data from our MySQL database with Ghost? Is there a way to do it within a handlebars template file, and if not, is there any way of importing it into the file?