How to run a js file from VSCode's builtin Node.js? - node.js

I need to run a js file from the Node.js that is builtin in the Electron which VSCode uses. Currently I am doing that by running a VSCode extension but there ought to be an easier way.
The code below should print the Electron version:
console.log(process.versions.electron)

VS Code does not expose functionality that lets users run arbitrary JS and this is unlikely to change. Using an extension is the correct approach

Related

make chrome extension using nodejs

Question Background
We are building Chrome Extension. and we need to get the python code in the process.
What i know
I know that python code can be imported using Node JS.
Node JS is used to create servers
Chrome extension is not building server, but making programs(maybe client?)
is it right?
Question
To achieve our goal
Do We need to create server with node js and communicate with chrome extension(using socket.io)?
Is there another way to apply node js in chrome extension?
Is there another way to get the python code into the extension?
Your Chromium web extension code necessarily must be pure client-side Javascript structured to run in the browser's extension environment. There's no support for nodejs or python in that environment; it's very constrained. Because cybercreeps.
You can use XmlHttpRequest or fetch operations in your extension code to access web services. Your extension manifest will need to grant permission to access your server.
You can meet your requirement by building and hosting a server for your extension to use. You can use nodejs and a framework like express and/or socket.io, or you can use python, python-socketio, and a framework like Flask or Django. If you build your server with python, it probably will perform better than a nodejs serves that spawns child processes to run python. It will definitely be easier to install, debug and maintain.

Why webpack and babel are dependent on Node.js to run?

I was learning babel and webpack and then it turns out I need to install node.js to run them both and I asked myself WHY? Then according to my research, we need node.js for webpack and babel since both of them were written in JS and to run that JS code which transpiles( for babel) and bundles up the code(for webpack). Also, another reason is that since both babel and webpack handles our JS code outside of the browser, this is the reason to use Node.js. Are these reasons true?
According to the Node.js website -
Node.jsĀ® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
Webpack and babel (along with many other tools you might use for frontend development) are written in javascript and since they are command line tools, they need a way to run outside of the browser (directly on your machine).
They could have used some other language to write the tools but since they chose to write them in javascript, Node.js is the only feasible options right now.
In case you are interested, the original creator of nodejs
Ryan Dahl has built another secure runtime environment for Javascript/Typescript called Deno
Yes, at the moment the node.js project is non-portable by full open source disclosure nor extension to port node.js commonjs without a just in time transpiler with a service worker on a server.
Definitions: FHC = "from half court"
Babel and webpack
(1) transpile/move (write&read, not ln -s sym...bolic link) & (2) compost/pile onto a JIT target,
like v8 or other browser-javascript-interpreters. v8 on a service worker can compile on the edge just in time for interpretation in a browser v8 environment but still on the cloudflare edge server.
Declare (FHC) Allegedly, rust provides webassembly modules with the lipid [llvm-]wrappings
that nucleic acid exocytosis needs to be a full-blown virus, err I mean
Initiation Routine needs to be a targetable JIT extension!
A compiler/transpiler still requires it's target-scope receivable. Declare (FHC) Emit is to execute as compile is to interpret, even AST.

React NodeGUI - Question about technology. Choosing Desktop Platform

I estimate possibility to write Report Desktop Application using React NodeGUI. There is some questions what I need to find answer before starting to develop by NodeGUI. Could you help me to figure out.
What way is to load program extension dynamicaly in React NodeGUI. For example: If I want to change business logic and visualization of my program without compile code. Is it possible?
What way is to load program extension dynamicaly in React NodeGUI. For example: If I want to change business logic and visualization of program adding some program module code of other developers. How way is it possible to do?
What way is to work with XML files in React NodeGui?
Is there possibility to run other program code written by C/C++ or other languages? What restriction of running non-native JS modules?
What way is to connect to SQL or NoSQL DB (PostgreSQL, Oracle, Mongo and etc)?
What are reasons yet to write or not write Desktop Applications by React NodeGUI?
React NodeGui is just another npm module that you would install in a nodejs program. It is a pure javascript library. It depends on NodeGui which is another regular npm module. NodeGui contains C++ code which acts as a nodejs addon. But for all purposes think of nodegui and react nodegui as regular npm modules. An app built with these libraries is a regular nodejs app.
What way is to load program extension dynamicaly in React NodeGUI. For example: If I want to change business logic and visualization of my program without compile code. Is it possible?
All business logic is written in javascript so any change in those would follow the same flow of how you would in a nodejs app.
What way is to load program extension dynamicaly in React NodeGUI. For example: If I want to change business logic and visualization of program adding some program module code of other developers. How way is it possible to do?
Yes you can use all npm modules available in npm that works with nodejs.
What way is to work with XML files in React NodeGui?
You can find a lot of npm modules you can use to parse and work with xml files in the npm registry.
Is there possibility to run other program code written by C/C++ or other languages? What restriction of running non-native JS modules?
Yes it is possible to run non js code by building them as NodeJs addons.
What way is to connect to SQL or NoSQL DB (PostgreSQL, Oracle, Mongo and etc)?
You have a lot of modules available in the npm registry for these which work with NodeJs.
What are reasons yet to write or not write Desktop Applications by React NodeGUI?
Reasons to use:
- NodeGui apps are native apps so they get all the benefits of native apps. They are snappy, they are accessible and run with low memory and cpu usage.
Reasons not to use:
Its under development so is only recommended for hobby projects as of Dec 2019.
PS: I am the author of the library

Angular + Electron app: query web API or DataBase according to deskop or web mode

I would like to build an app using Angular + Electron. My app should be able to run both on desktop and browser platforms. I'm considering to use angular-electron starter kit (but I'm open to other possibilities).
What concerns my is the way I read and write data. The data must be stored in a MySQL database. Ideally I would like to:
make the app call an api when NOT running on Electron (browser mode)
make the app query directly the mysql database when running on Electron (desktop mode)
I know I could check for window && window.process && window.process.type to let the app understand wheter running on Electron or not, however I'm a bit concerned about how to handle this. Also because I probably need to import node packages like mysqljs but ONLY in the desktop mode.
You can simply pass in different environment files in Angular during build this allow you to control the environment variables so that you can tell that it is a web app build or an electron app build.
https://angular.io/guide/build
EXTRA
But if you are importing binary packages this is where it gets tricky. I dont think there is a clean way for you to do conditional imports. I did not manage to find a way to do it cleanly and sort of maintained another repository for all my services that needs to import binary files.
To import the binary files you will also need to edit some webpack settings to tell angular to not compile/include the binary files during the build process so that you can use you librarys like mysqljs that require binary files. There is also some settings on the electron end to make binary files compatible for different platforms ie Windows, Mac , Linux. Basically it is really a pain to do it.
Link to how to edit webpack settings for angular 7+
https://github.com/manfredsteyer/ngx-build-plus
I will totally suggest you not to do it unless you really have a very good reason that you need to use these libraries.
EDIT 10/1/19
Okay I was referring to the MySqlJs but it seems like it does not have native modules modules. Native/binary modules basically means javascript code that relies on c++ compiled binaries(Or any native language like rust...).
For my case I was using the grpc modules which has a native dependency. Had to switch to grpc-web in the end.
I will add some footnotes here if you ever need them
https://electronjs.org/docs/tutorial/using-native-node-modules
Node.js / npm - anyway to tell if a package is pure JS or not?

Using Node.dll binary to execute JS in Win32

As the title says, I would like to run a JS file from within my application. I dont want to create a node.exe process. Is there any sample example to start with?
Edit:
I plan to use standalone dll that comes with electron installer - https://www.npmjs.com/package/electron-installer-windows
or build it myself using electron instructions
If you just need run JavaScript in a Windows app, you can use ActiveScript instead.
Otherwise this doesn't seem like a programming question.

Resources