i have built a microservices application using NodeJs . i have building this app for 4 month now and it starts to be big. i have used private modules to share code between the services but now i face anther problem.
i am getting duplicate code for requiring this modules(and public modules) as many of them are being used in all the services and are called in my index file.
so what i have try to do is build anther private module that it`s purpose is to include all this modules dependencies and control all the updates .
that works good, the problem is the IDE "phpstorm" screams on me because now those dependencies are not in the service package.json and also i dont have autocomplete on them(same reason) .
is there a way to let the package json to use this dependencies from that package , or maybe anther technique to achieve this
IntelliJ might be providing a separate IDE for node js could you look at it, I use Atom or VS code(sometimes) for node related stuff. Maybe take a look at this as well.
Related
Let's say we have a package on NPM like got.
I want to figure out which core NodeJS modules this package is using as I want to polyfill it on environments (like React native, or the browser).
Is there any way where I can just get a list of which core NodeJS modules this package is using without manually searching through the source code?
I know there are ways to figure out the dependency tree -- that is not what I am asking. I specificially want to know which core NodeJS modules are being used.
There is no way to do this that is not manual unfortunately.
However, it is pretty simple to do.
Simply search all the files in your project via your IDE. CMD+F for things like crypto, buffer, stream, etc.
https://flaviocopes.com/node-core-modules/ is a list of all the core node modules
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.
I've started to convert my project to typescript and in a meanwhile I decided to improve code reuse between node.js backend, react web client and react-native mobile client.
Here is my project structure:
├ commons (code shared between backend and frontend, mostly type definitions and utils
├ clients (code shared between web and mobile clients, depends on commons: containers, utils, forms... )
├ backend (express server, depends on commons)
├ web (create-react-app, not ejected, no SSR needed, depends on clients)
├ mobile (react-native client, depends on clients)
What I've tried so far:
Symlinks. Could't make them work with react-native (see metro bundler issue).
This can probably be solved by using haul, but adds extra complexity by making haul work with typescript. Also, haul doesn't seem to work with Mobile Center, which I use for publishing mobile apps
Using rootDirs or paths in tsconfig.json. Typescript compiler doesn't merge/bundle outputs, so this means I need to support 3 different solutions to merge generated code. Also doesn't work well with my IDE.
Using WML. I tried two approaches:
Linking commons and clients to packages inside node_modules of web/mobile/server. To do this, I have to generate declarations, which is burdening because it requires exposing all imports (see this issue). Also doesn't play well with yarn, which will remove linked package every time it installs something new.
Linking commons and clients to separate source folder inside source folders of web, mobile and backend. This is what I use in current JS version of my project. It works, but it has some downsides:
Long relative imports (probably can be solved by supporting 3 different solutions for module aliases)
wml sometimes breaks in backround, which leads to some confusing albeit easy to discover errors
doesn't work well with hot reloading
I'm looking for a solution which is not too complex (requires minimal configuration on web/mobile/backend sides) and plays well with Webstorm.
It probably doesn't exist now, so I'd like to hear what other solutions people here use for similar project setups.
In the similar situation to yours I did the following:
commons gets published as a separate npm package. You can make it private if necessary.
clients depends on commons package and gets published to npm as well. Again - private if required.
web and mobile projects both reuse npm packages created above.
I am working on node js application and it is now ready to use. I want to make exe of this application so that it can be used for commercial usage.
Up to now I have used enclose module using which I have compiled the code of application but I have found some issues in that (app got crash on idle condition). App is running good without enclose or compiled code.
I have searched on google and found some alternate modules like JXcore, Node webkit and Electron etc. but JX core giving error same as in SO question.
In node web-kit, it's functionality is not looking suitable as we need its executable and some dll's along with our code, which makes our package bulky.
I have also tried jxcore. The main problem with the exe's and with modules that we use is their ability to work with native modules, in my case the Kinect.node module. This module cannot be compiled. We need a workaround to package only this along with our .exe file. Enclose provides this workaround in its inbuilt functionality.
Also looking a response from EncloseJS, which is actually run by just one person who gives further instructions upon purchase. A purchase is needed for commercial usage.
In case of Electron, It is supporting only Electron-based application source code. So If I choose this then I have to modify my application code.
So can any one suggest me what can I do to make exe file from node js code there?
Thank you!
I had the same issue before, the node js application close when running in background. now i am using process manager2 (pm2), it is working fine and if the application is crash due to any other reason it is automatically started again.
I have gotten my answer:
First, reason was DiskDB database, it was not compatible with the node webkit so that is why I was getting error of native modules.
Now I am using sqlite3 module for local database. It is better than DiskDB.
Second, One reason was free version of enclose, Paid version of Enclose JS module ignores the timeout issue which I was getting.
This way I have resolved my question.
All, I am trying to using third party NodeJS SDK in Titanium Studio. However, I consistently encounter dependency issues, such as util.js, utils.js, ms.js, events.js etc. I tried to add the missing module manually, but it looks like it will become un-tractable as there are so many dependencies.
My questions are :
1. Is that possible to use NodeJS based SDK in Titanium Studio .
2. If so, what is the right approach to include the dependencies.
Thanks a lot!
Titanium can't get Coffee scripts to work natively (assuming you want to deploy the TitaniumWrapper.coffee). A possible solution you may want to try is hooking a plugin http://billdawson.com/titanium_coffee_script/ in order to pre-compile Coffee scripts.
You can also try to embed everything using a Tiwebview that wraps HTML to load mojio-js.js but you would still need to observe events mojio client (like replacing keys, login an user and create a few model instances).
Hope you find the info useful and can serve for further research.