Whether it's a mule or a horse, you have to pull it out to find out, right?

After checking it out, there are currently two main options for developing desktop applications with Nodejs.

  1.Electron

  Electron is a framework for developing cross-platform desktop applications using Web technologies. The project address is: https://github.com/atom/electron

  2.NW.js

  NW.js is an application runtime environment based on node.js and chromium written by Intel engineers. The project address is: https://github.com/rogerwang/node-webkit

 

  1. Download of NW.js

  The official website address is: http://nwjs.io/

  After entering, click to download the SDK version and unzip it to the local directory.

  

 

I encountered a depressing thing here. The 0.30 version of the zip package downloaded from the official website could not be opened, and it prompted that there was an error in the zip package.

 Neither does using 7zip

Still downloaded from the official website, really served. I downloaded it 10 times and it didn't work. .

 

Can only be used with a 0.23 package downloaded from other sites.

  2. Application writing

  1. Create a helloworld folder in the nw.exe directory.

  New index.html

  

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Hello zhupengfei!</title>
    <script src="helloworld.js"></script>
</head>
<body>
    
</body>
</html>

  

Press New helloworld.js
document.write('Hello, World!');

  New package.json

{
  //The entry page of the application (can also be set as a js file)
  "main": "index.html",
  // application name
  "name": "HelloWorld"
}

  2. Run helloworld.

  a) Press shift+right mouse button in the directory where nw.exe is located, and select "Open command window here". Then enter nw helloworld to see the running effect. Note that it is recommended to use cmd, not powershell. I have to use ./nw to use powershell.

  b) You can directly drag and drop the helloworld directory to nw.exe and it can also run.

  3. Application Packaging

  General Windows desktop applications are all exe executable files, which do not depend on other files and environments. The helloworld application we created depends on nw.exe and related files, so how to package the application into an executable file?

  After google, there is indeed a solution, that is Enigma Virtual Box

  1. Download Enigma Virtual Box

  The address is: http://enigmaprotector.com/en/downloads.html

  Just select the last download and that's it, then install.

  2. Package the application into a helloworld.nw file.

  Go to the helloworld directory, select all three files and pack them into zip, and then change the name to helloworld.nw.

  (There is a pit, I read it from the Internet and said that it is not possible to compress it into ZIP with WINRAR, and 7-zip must be used, so it is passed directly here.

  

  3. Merge helloworld.nw and nw.exe

  Move the helloworld.nw file to the same directory as nw.exe, and then execute the command. Note that nw.exe must be in the front.

copy /b nw.exe+helloworld.nw hello.exe

 

  Found an additional hello.exe file, double-click to find that it can be run. However, this is not the final result, because after moving hello.exe to another folder, it cannot be executed normally.

 

  4. Use Enigma Virtual Box to package it into exe. After installation, you can choose Chinese display in the language.

  

 

  Input File Name select the hello just generated, Output File Name is the output file.

  The point is, the following Files need to drag the locales and pnacl folders into it, and then add select all the files in the nw.exe directory that do not contain the helloworld application we created

  

  Then click the "Process" button in the lower right corner,

  

 

 After packaging, the file is too large, 144M. I'm dizzy, this is just a demo.

  When you see the results in the above figure, it means that the execution is successful.

  Find the packaged file and execute it.

  4. Encryption

Encryption must use the SDK package. The runtime package was downloaded at the beginning. I don’t know. Later, I downloaded the SDK package and found that there was nwjc.

The encrypted string is added, and it is convenient to confirm whether the encryption is successful.

 

 

Execute the following command to encrypt the JS file as a bin file

$ cd helloworld

$ ../nwjc.exe helloworld.js helloworld.bin

There are two more files.

 

 

 

 The content does output.

 Then follow the same steps as above, modify the compressed zip to nw, then merge, process and so on.

Personal summary:

Personally, I feel that the two are similar. I did a demo with Electron yesterday, and the effect came out. not bad. Try it with Nwjs today.

Why use Nwjs? The reason is that Electron currently cannot support code protection, it can be compressed asar, but it can be decompressed. Most desktop applications are commercial projects, so I think code protection is a must.

Last night, I watched Electron's github for a long time, and finally came to the conclusion that eclectron did not plan to add code protection functions to the project, because they thought that most people would not use it.

So I think it is better to use traditional .net java C++ for desktop applications. Like nodejs python, it is full stack. In fact, it can still be used as desktop application at most.

------------------------------------------------------------

  If you have any problems, please contact me on WeChat

Or contact me with Alipay