Node.js runtime wrapper - node.js

Are there any node.js runtime wrappers generators similar to gradle wrapper that allows to build node.js application without installing the node runtime globally?

Yes, there are many projects that aim to make bundling Node.js with your apps easy:
node-bundler
Nexe (doesn't support dynamic require statements)
EncloseJS (paid)
If you're starting a GUI project from scratch, then Electron or NW.js allow you to bundle up a browser with your app to allow using JS, HTML and CSS.
There are also some experimental JavaScript-to-uninterpreted compilers in the work:
ts2c converts TypeScript to C which can then be compiled with gcc or clang, and there's an unreleased project called Nectar that aims to compile JS to machine code directly.

Related

Why Electron need to use the native modules? Electron embed a Node.js in it, whether this do not have the special `native modules`?

When I read document using-native-node-modules:
Native Node.js modules are supported by Electron, but since Electron has a different application binary interface (ABI) from a given Node.js binary (due to differences such as using Chromium's BoringSSL instead of OpenSSL), the native modules you use will need to be recompiled for Electron.
I have several questions about it:
how to understand Electron has a different application binary interface (ABI) from a given Node.js binary?
what's the function of application binary interface (ABI) in there?
the native modules you use will need to be recompiled for Electron. , why Electron need to use the native modules? Electron embed a Node.js in it, whether this do not have the special native modules?

Trying to understand "Since Electron is very likely to use a different V8 version" explanation

Electron Documentation page Using Native Node Modules includes the following explanation:
Native Node modules are supported by Electron, but since Electron is
very likely to use a different V8 version from the Node binary
installed on your system, the modules you use will need to be
recompiled for Electron.
As an Electron newbie, I know about the main Node.js process and the renderer processes, but the above explanation still makes no sense to me. An explanation of what the above is saying, and why one needs to worry about V8, would be welcome.
Note that this is talking about "native node modules" which I assume means modules that use some "native code" and use the add-on library interface in order to extend node.js with native code.
Electron packages a specific built of node.js in it's build tools. Some modules you use (like the ones that are not 100% javascript, that include some native code) may need to be "built" for the specific version of node.js that you're running.
So, all they're saying is that if you're running node v12.13.1 on your development computer, but the version of electron you're using has v10.x in it, then if you have some modules you're using that have native code in them, you may need to rebuild them for the version of V8 built into your electron environment. This wouldn't be so much because of the variations in the Javascript engine (those aren't usually dealt with by compiling), but because of variations in the add-on library that "native code" modules use.

Can expressjs be faster if I compile it?

There are tools that help us now to compile or node.js apps into executable such as "pkg". But I am interested If this can improve a web server written in expressjs?
No, web servers based on the Express framework will always require running on the V8 JavaScript engine of Node.js, which is also used by the Google Chrome browser.
You cannot compile a JavaScript program to machine code and run it standalone, like you can with programs written in C++.
If you create an executable program with JavaScript, for example using Electron, it's actually just a modified Chrome browser that runs the JavaScript, so the JavaScript is not actually compiled, it is still code interpreted by the modified Chrome's V8 engine at runtime.
Chrome and its V8 engine are written in C++ and compiled to machine code, so they can be run standalone.

What are some mechanisms to package cross-platform Electron apps in a single build?

I'm developing a desktop application based on Electron and I use electron-packager to create executables. The app uses some binary node modules such as bcrypt.
On my Mac, I package the app, targeting both OSX and Windows. The resulting package runs fine on OSX. But when I run the resulting Windows package (.exe and dependencies) on Windows 8.1 64 bits, the app throws an error (quite expectedly):
Is there any practice or tool that helps me be able to do the packaging once in any OS, even if the app depends on binary modules, and produce executables for Windows, OSX and Linux? For example, I'd like to run the build on OSX to produce executables for all three operating systems, instead of having to repeat the packaging for each platform
You should look into removing native binary requirements from your project if possible. For example the module you mention, bcrypt, has another implementation which is full JS and doesn't require native binaries: https://www.npmjs.com/package/bcrypt-nodejs
If you really need to include compiled binaries as a part of your dependencies you're probably going to have to design that part of the build/packaging automation yourself.

cloud9 node.js addon debugging

I'm working on a node.js module which uses native C++ addons. I plan to move my development from vim+nemiver+node-inspector to something more integrated. For that c9 seems to do the job.
Is it possible to debug both javascript (with v8) and C++ (with gdb) at the same time?
My old setup supports this by using nemiver and node-inspector side by side, but it isn't a very pleasent workflow.

Resources