This is a beginner kind of question. I haven't used NodeJS before, so it's a bit confusing to me. I don't see a clear separation between server modules and client modules. It seems like I can use "npm" (Node's package manager) to install both client modules and server modules.
My question is specifically related to this page: http://electron.atom.io/docs/v0.36.8/api/synopsis/
It says that I can use Node modules on client side:
The renderer process is no different than a normal web page, except for the extra ability to use node modules:
<!DOCTYPE html>
<html>
<body>
<script>
const remote = require('electron').remote;
console.log(remote.app.getVersion());
</script>
</body>
</html>
How does this make any sense? Node is running on the server side, how is the browser ("renderer" process as they call it) able to use Node's packages?
Node. js is an open-source server-side Javascript run-time environment built on Chrome's JavaScript Engine(V8). Node. js is used for building fast and scalable applications and is an event driven, non-blocking I/O model.
js application. In client-side we mainly deal with DOM or web APIs like cookies, but these things don't exist in Node. Other reasons why we cannot use node modules at the client side is that the node uses the CommonJS module system while the browser uses standard ES Modules which has different syntax.
On a desktop app, you don't have to have a server. But with electron you can use node direct in you app. The easy way: With electron, think of NodeJS as a Toolbox to do cool stuff. Like Filesystem manipulation and forget the client and server thing.
Node. js allows developers to write JavaScript code on both the server and client side. Compared to other languages, Node. js code execution is faster.
main process & renderer != server & client
NodeJS is Server side, not client side.
On a desktop app, you don't have to have a server.
But with electron you can use node direct in you app.
The easy way: With electron, think of NodeJS as a Toolbox to do cool stuff. Like Filesystem manipulation and forget the client and server thing.
(Things you cant do with jquery etc. but things you need for a Desktop-App)
The main process is for handling/creating BrowserWindows(Renderer) And for some communication from one renderer-Window to an other one. (maybe some other special stuff too)
The renderer is where you really run the most of your app. With node, you have all you need there. Easy debugging (chrome dev tools) all in one place.
You can require "fs" > NodeJS File System
To read Files or Folders from your Harddrive.
You can do this for a example in the html File (script tag) which is display by the Renderer/Browser window.
It was very confusing for me too and my answer is for sure not perfekt and fully right. But my tip is, try do everything in the renderer. When you have to use the main process you will notice that.
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