Virtual Env for nodejs application - node.js

We are running a nodejs application, but we want to run different version of same application, how we can achieve this, like python virtual environment.
I have seen nodeenv, but from the examples, it seems it only provides different versions of node binary to run, but not nodejs application.
With regards,
-M-

When you have different versions of the same app, I assume that you will have a different package.json file for each version of the app? And you probably have the different version of the app resides on different folder?
Are you in a Linux environment or windows or Mac?
Can you use a .sh/bat to invoke the npm start on different folders ?

Related

Could i use differents node versions between my project and specific library?

i will try to give you a little of context.
With my team we are trying to migrate MUI v3 to v4 in a reactJs project. We did it with the project itself and it works! but, some kind of problems came up when we navigated to certain windows that use a certain library to work.
This library was developed by other guy that is not in the company anymore and we are not in touch neither, but, we have access to the library GitHub repository, them are two actually.
https://github.com/rjpizarro/forms
https://github.com/rjpizarro/make-request
i've never had to do this so, i decided to clone the project then install the dependencies and run it.
I'm using nvm so in that moment i was working with node v12 and i got some errors when i executed the npm start ("start": "webpack --watch").
If i use node 10 the scrips runs perfectly but in the entire project we are using node 12 so i'm not sure what is the problem here.
i'm wonder if it could be a problem when i'll try to migrate from MUI v1 to v4 and use the modified library into my project again, or in first place, why its working rigth now?
Anyway i just wanted to know, just if i need it, Could i use different versions of node in a library and then use other newer version into the entire project?
Could this make some negatives effect into my entire project?
Which is the best way to migrate MUI into this library and put it in my project again?
Each nodejs process (including all the modules/libraries it loads) has exactly one version of nodejs running. It isn't possible to have two separate versions of nodejs in the same process each running different parts of the code.
You could make two separate nodejs apps that each run under a different version of nodejs that communicate with each other via some interprocess communication, but they have to be two separate applications/processes.
If you want to run everything in one process (on one version of nodejs), then you will need to test and fix all your libraries to run on that one version of nodejs.

How to run multiple nodejs version on a single server?

I want to run multiple NodeJs versions on a single system.
For EX:- I have two nodejs apps. One app are running nodejs version 10.xx.xx and another one is running nodejs version 12.xx.xx.
here I want to move both apps on a single server.
how is it possible..??
Package each app using Docker Container then each app will have his own nodeJS version without issues because of the isolation.
You'll find official nodeJS continer in here https://hub.docker.com/_/node/

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?

can i play with node.js on a web based console?

I have a temporary situation whereby I am unable to install node on my computer. Is there a web based lightweight terminal I can play with and learn node by doing it?
Thanks!
check out cloud9, they offer a whole development environment (also for JavaScript - node.js).
NPM uses RunKit for this purpose. You can use all of the packages available on NPM and its free too. https://runkit.com/home

How do I use NodeJS on Asustor AS-302T NAS

I have recently bought a Asustor AS-302T NAS, which is an absolutely brilliant solution for the home. One of it's most impressive features is that you can install apps which extends the ordinary behavior of a NAS. And if you are a developer you can also create your own apps.
While apps are fun, I have more interest in using my NAS as a kitchen-sink for my personal nodejs projects. In short I want to run nodejs application that I can then call from various other machines around the house. My own mini-cloud for IOT experiments.
Installing, one click only
Having installed NodeJS through App-Central I am at a loss how exactly to start using NodeJS on my NAS. The whole installation is essentially an on/off switch with no options or visible settings at all. I can find no documentation on practical tasks like uploading a nodejs application, deal with access rights or even execute it.
Under Windows or OS-X I would use npm via the command-line or shell, but Asustor is a purely html based interface (with the exception of XBMC through HDMI).
Why offer to users the option of installing NodeJS -if it's impossible to actually use it?
So my question has three aspects to it:
How do i get access to npm on my Asustor NAS
How do i get my NodeJS application running
Is it possible to run my application as a service (executed when the NAS boots)?
From the ASUSTOR Developer's Guide: apps are installed into
/usr/local/AppCentral/$APP_NAME.
NodeJS executables will be at path /usr/local/AppCentral/nodejs/bin/node and /usr/local/AppCentral/nodejs/bin/npm.
You can login to NAS via SSH and add them to PATH variable, or create symlinks...
I'm also searching for solution how to run them as a service (daemon), maybe an /etc/init.d script might help.

Resources