Using node js for storing form data

Dear forum,

I’m currently developing a theme for a client and I’m using Ghost 3.12.0 as a Docker Image.
I need to store data submitted from a HTML form into a .json-file. Imagine for example a guest book: username, data and message should be stored inside a .json-file on the server.

Since so far I have only worked with HTML, CSS and JS in terms of theme development I was searching for ways of achieving this and fount that node.js would be the best choice.
As far as I understand Ghost is built around node.js and it is also installed inside the docker image (checked with “node -v” inside the bash of docker image).
My questions is now if it is possible to use node.js modules from within Ghost?

All information I found so far was not really clear to me.

Best regards and thank you in advance,
Jonas

As far as I understand Ghost is built around node.js and it is also installed inside the docker image (checked with “node -v” inside the bash of docker image).
My questions is now if it is possible to use node.js modules from within Ghost?

Yes you can but modifying the core Ghost code is usually advised against. If you want to retain the ability to easily update, I’d suggest setting up a separate service that will receive your form data and store it somewhere. Maybe use something like Firebase client-side.

Thanks for your answer.
Would it be in theory possible to build an own solution using php? For example having stored a pre-generated .json File inside the theme directory and pushing new data into it when a form is submitted?

Sorry, I’m not really familiar with PHP. I would assume you’d have to set up a separate backend service to do so.

If you just want to save user submitted data there are likely easier ways to collect and store this information. If you’re comfortable writing JS you could write a script that will take the inputted data and submit it to a Google Firestore. This way you only need to worry about the sending the information to Firestore and it will save it to a NoSQL DB for you.

Then you could have your JS included as part of your Ghost theme.

1 Like