How to safely deploy nodejs script

Viewed 22

I have a NodeJS file that processes IoT data. It runs on a domain, and I have a different DOCROOT for this domain, point to /public.

Ideally I would store my main.js file outside the public folder so the javascript source code remains protected. But how would a user be able to interact with the server? Would that be to create a public/main.js, that includes the main.js file from the public parents folder. Is this correct?

So my guess is that the folder structure would be like this:

/node_modules
/public
/public/main.js
/.env
/.gitignore
/main.js
/package-lock.json
/package.json
/README.md

Is this how one would safely deploy a NodeJS server script? Or should it be done differently? I'm sorry if this is an inappropriate question, but I'm new to NodeJS and would appreciate some guidance.

1 Answers

Nodejs is usually server-sided and not client-sided, meaning you would need a server/host to run the code (just like you need to run "node main.js"). There are many options out there, but as an example you could use heroku.com.

When the scripts are deployed on a server/hosting platform, the users are not able to read the source files (as long as you don't make them available within the code).

In order for the users to be able to interact with the data/server you would need to create a endpoint that allows the users to connect to the server. You could for example use the npm library called "express". This would allow you to create different endpoints on the server that the users can access.

Not sure how much this helped or if I understood this correctly, but let me know :)

Related