I heard that node js can be used in server side. I used jsp before. Inside jsp page java code is invisible to client. If node js is just javascript, then how it remains invisible to client?
First of all, Node js is not a programming language. it is a run time environment so there is no node js code, only javascript code. this javascript code runs in node js environment.
Just like Java is a language and JRE is a Run time Environment, javascript is a language and Nodejs is a Run time Environment inside a machine/server.
Node.js runs on (more specifically can be installed on) various platforms (Windows, Linux, Unix, Mac OS X, etc.).
Node.js uses JavaScript on the server just like we use java servlets on tomcat server.
JSP is a piece of code embedded inside html pages which can create dynamic content by interacting with databases and JSP code is hidden from the browser. JSP code runs on Java capable HTTP servers like apache tomcat to process. Here, all the JSP code in turn converts to servlets and replaced with appropriate content and sent to the browser/client.
Javascript can run inside a browser with the help of v8 engine but there is no restriction that javascript only runs in browser. javascript can run inside a node js run time environment to interact with databases/filesystem etc.
Now that you mentioned JSP, so i assume you are talking about server side rendering.
In server side rendering, using node js, for front end logic, we create a public folder, inside public folder, we write the javascript which should run inside browser like, animations, API calls etc. this javascript runs inside browser and is visible to client. it should ideally not contain any sensitive information.
outside this public folder, we write all the sensitive javascript which runs inside node js server and is not visible to client as it runs on server side, in a way java servlets works.
because it is javascript at both places, we get confused.
Server side code is not visible on client side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With