Although Node is known as a server platform, interest in using it to build Windows desktop applications is growing rapidly. Bindings exist for GUI toolkits such as GTK+, QT, and Cocoa. However, one of the advantages of Node for web development is the ability to use the same language on both the server and the client. It functions well together with a web browser shell to develop cross-platform desktop applications and JS Windows games using WebGL with HTML, CSS and JS.
A brief history of the code
Thanks to the improvements made to the ECMAScript specification, JS has become the modern programming language for browsers. Thanks to its ubiquity and ubiquity, it has become one of the three pillars of the Internet along with HTML and CSS. However, the current level of IT usage requires running outside the browser.
There are times when the user needs to include external code in their own program. For example, when using jQuery, the removed tag is inserted, which imports the functionality of the application. The same goes for regular scripts that users write themselves. You can simply import any JS file with the removed tag. However, this can get cumbersome and have to manually manage hundreds ofdependencies.
In this case, Node.js comes to the rescue. How? Before installing Node JS on Windows or another OS, the user does not need to do any device upgrades, since the software provides an easy way to manage dependencies. It comes with a package manager (NPM). Through it, external data can be imported into user projects as dependencies.
Scope of packages:
- Database management.
- Web applications.
- Desktop and mobile apps.
- Fast code execution.
- High scalability.
- Multifunctionality and asynchrony.
- No buffering.
Browsers have a built-in interpreter for JS. Node is both a framework for it and includes a set of libraries for using JS as a general-purpose programming language with an emphasis on asynchrony and non-blocking operations. In fact, the code runs the same interpreter as Google Chrome (V8), but provides a different set of libraries and a different runtime. It also includes a package management system (NPM) and several language extensions that browsers don't have, such as modules.
Thus, the JS interpreter in Google Chrome and the equivalent Windows JS application program in Node are essentially the same. The difference is that in the browserthe end goal is to change the content of a web page - text, graphics, stylesheets, and more, and in Js - running general purpose code that can do anything from activating a web server to manipulating files.
Any existing web application is good enough to become one. It can be built from code that will benefit from being integrated into the user's system, from startup notifications to interacting with files and other desired programs. Some simply prefer to have certain applications permanently on their machine, available whether they have a connection or not.
It's easy to create powerful desktop utilities using web technologies like NW.js. Such programs have been around for a long time. In Shanghai in 2011, Roger Wang of the Intel Open Source Technology Center wrote node-webkit, a proof-of-concept module that allows the user to create a browser window and Node.
After some progress and transition from WebKit and Chromium, the open source software on which Google Chrome is based, Chen Zhao joined the project. Together they created an application runtime for Node and Chromium. The node-webkit project became quite popular and was later renamed to NW.js.
Both projects are built on top of Chromium and Node so you can write desktop applications using it at the system level and web technologies at the GUI level.
Electron has some advantages:
- More popular with developers.
- Has the best corporate support. Github and Microsoft are behind Electron, and NW.js is sponsored by Intel.
- Offers an automatic update mechanism out of the box.
- Building it is a bit easier because you don't have to combine all of Chromium.
- Legacy support: Windows XP and older versions of Mac OS. Despite the fact that Microsoft has dropped support for XP, but many users still use it, so they really need this service.
- Application master entry can be either an HTML page or a Node.js file.
- It's more browser oriented.
- The approach to it is much simpler and clearer. This gives users many options.
- Separate and mixed contexts.
- Chrome extensions and Chrome API support. What's more, you can run Chrome apps and extensions with NW.js. "Electron"cannot and will not do so.
- Supports PDF files out of the box using Chrome's own PDF plugin.
- Uses latest version of Chromium
- You can use the software without Dev Tools.
- Supports Chromium command line switches. For more information, please refer to the NW.js documentation. These switches can be used for performance tuning.
- The best security model for desktop applications. This is somewhat limited in Chrome (and web browsers in general) due to the nature of the user's relationship with websites. NW.js provides a different model that allows you to bypass all security restrictions such as sandboxing.
Getting started with the program
There are two versions of Node.js available for download. At the initial stage, it does not matter which one to choose. The Long Term Support version is considered the most stable. It is updated only when necessary for bug fixes and basic maintenance. This version is preferred in production environments and is much more stable. It is frequently updated with new features.
With a faster update cycle, the software has the most up-to-date APIs and technologies for developers. After going through the installation process, you can verify it by opening a command prompt.
Code can be divided into import and export modules. NPM provides an easier way to manage dependencies. Let's say we need to use Lodash in code. First initialize a new project by running npm init in the project directory. Upon request, fill in the necessary information about package.json. All metadata is stored here.
Assuming the user is in the correct directory, do this by running npm install lodash. The dependency is downloaded to a folder named node_modules. She tends to accumulate many files as soon as they are entered.more dependencies in the project. After installing Lodash, create a JS file in the current directory that Lo Dash uses. It imports Lodash by calling the require function.
As mentioned earlier, Node.js provides an API. This is a built-in module that comes with every installation. You can import this code by also calling the require function. Running the JS file will write Hello World to text named dev to.txt.
This fs.writeFile method is just one of the many fs functions offered by the module. All available API methods and properties are described in the documentation.
Say there are four JS files in the same directory named index.js, add.js, username.js and dog.js. The job of add.js is to provide a function that returns the sum of two inputs. You can export it by assigning the add parameter to the module.exports property.
The job of username.js is to export the string Some Dood. Or whatever. This means that you can assign a value of any type to module.exports. This means that they export strings, numbers, booleans, symbols, functions, classes, arrays and objects.
You can call these three index.js files using the require function. Need to provideabsolute or relative paths to them to explicitly tell Node.js that they are importing from files and not from built-in modules or from the node_modules folder of the project, while you can omit the.js extension. The "required" function returns the actual value that was assigned to the corresponding module.exports file.
Installing and launching the application
A very simple first step into the world of JS is done using the command line and writing the first bit of code Node.
Algorithm for running Windows JS script:
- Download the latest version of the program, for example, V6.2.2.
- Install Node npm install following the instructions.
- After activation is complete, find the icon in the Windows search option and open the program.
- Now we can go ahead and do some calculations and try to print messages to the console.
- The steps will show that the node has been successfully installed on the system and is working properly.
- Press Ctrl + C twice to exit the node and get the directory path again.
- Set up the Windows command line environment for the application.
- Download and install from JS developer site Windows open.
- Run cmd.exe.
- Press Windows + R on the keyboard.
- Type cmd and press enter.
- Check if node installed successfully by typing node -v, it should reply "v.. ", where "" means number
- Reboot the computer if the -v host does not respond correctly.
- Try to automatically install all dependencies using npm commandinstall.
- Start the server by running "node application" in the root folder of the server.
If the previous step failed, install the dependency manually by running the following commands:
- "npm install";
- "npm install express -g";
- "npm install url -g";
- "npm install fresh -g";
- "npm install cookie -g";
- "npm install crc -g";
- "npm install send -g";
- "npm install connect -g";
- "npm install commander -g".
Configuring Node JS Windows 10
Developing with js for Windows used to be pretty cumbersome, but now it's much easier. The network has the latest tools and applications with the ability to use the 64-bit version.
- Install Git using default settings.
- The Projects folder in the home directory is chosen as the installation location, if it does not exist, then it is first created for the project.
- Right click on the folder, select Git bash here and check the git version by typing: git-version.
- Create a.bash_profile that will be executed when a bash window is opened. This is not a cmd.exe window, so check the options. Click on the icon in the top left corner. You can paste text using the middle mouse button, as on popular Linux terminals.
- Install Node.js on Windows 10 using the LTS version. Notit is recommended to activate multiple versions at the same time as the node manager (NVM) does not officially support Windows, but there are alternatives such as nvm-windows or nodist.
- Node comes with npm, a package manager available after installation.
- Open a bash shell and check versions with: npm --version. If npm is 2.x, you should update it to version 3, which solves many problems, such as handling peer dependencies.
- Find Powershell in the start menu, run it as administrator and install npm, the Windows 10 package manager.
- Activate Visual Studio and Python. Node packages usually depend on native code packages, so you need to install Visual Studio. Node-gyp is a wrapper for the Python GYP. It generates project files for Gcc, XCode and Visual Studio.
- Install Python by downloading the x64 branch. You can go with the default settings and also select the "Add to Path" option. This will add the Python binary to the global path, which means you will eventually have to log out and log back in.
- Install Visual Studio.
Node.js projects usually rely heavily on environment variables. You can use locally installed node modules in the script section of package.json. Recommend not to activate packages globally with npm –g.