Node.js server code protection

I am developing my next web application with node.js. For example, with ASP.net, server-side code .cs cannot be accessed from a client browser. I want to know, when I develop my application using node.js, the server.js file is protected from users viewing my site. I mean, I do not want visitors to my website to have access to the .js server code. Can I protect these files with CHMOD file permissions, will this help?

+6
source share
2 answers

If you use Express.js as a web server, you have a “public” folder in which you put your static files, which are served right up. Outside of this folder, you have other sibling folders where you keep your code as “controllers” and “models”. You cannot navigate to one of these folders through a web browser so that they are inaccessible because your web server root directory is "public".

project_root/ - app.js - public/ <-- web root - javascripts/ - stylesheets/ - images/ - some_static_page.html - controllers/ - models/ - routes/ - views/ - node_modules/ 
+8
source

This is not because Node.js uses Javascript to make your files magically accessible in the browser. In Node.js, as in Asp.net, there is a difference between the client and server sides. If you do not submit your Javascript files to the client, they will not be public.

+1
source

Source: https://habr.com/ru/post/915548/


All Articles