Process Javascript Serverside and send it back to populate HTML page?

Hello all,

I’ll start by saying I understand that the premise of my question is inherently the opposite of what a static website is.

Basically I would like to have a site where the user can provide some inputs, submit a form, and then a JS script would run server side and pass the results back to be then displayed to the end user. The reasoning is that I’d like to hide the JS code itself as it could be seen as proprietary. I’m already minifying the code, but simple descramblers would probably undo the minification easily.

The rest of the site functions perfectly as a static website and is perfect to my needs, which is why I’m hesitant to start from scratch to build a dynamic site.

Do you know any way that this is possible?

Thanks!

May be node.js/npm is what you’re looking for

Is there a specific package you’d recommend?

For what exactly? Your question is so general that all I gathered from it that you want to process user input server side with JavaScript. You didn’t say why you’d want to use JavaScript nor what you are going to do with the user’s input. So I blurted out the only thing that came to my mind when reading “JavaScript” and “server side”.

You could equally (or may be more easily, depending on your server setup) use PHP, Perl, Python, probably Ruby, Java, whatever. All this has nothing to do with Hugo, it is about what used to be called CGI: Take a HTML GET/POST request, interpret the parameters passed by a program running on the web server and return something to the browser.

Once you are running a full-blown webserver, why not just run a CMS? Then it’s trivial to capture user input, manipulate, store and serve it.

Honestly, I’d probably use SvelteKit and use an endpoint for that. You can SSR most of the content and then have a component on a page that calls an endpoint to get data to update page contents with. It’s fairly easy to deploy this to a service like Netlify where the “server-side” code runs in functions.