I am creating a custom plugin for kibana. I have done all the actions needed to initialize the new app and it is working fine.
The app is visible in the kibana’s interface and I can access the app’s form by clicking the app’s button in the side navigation bar.
I can also access the app’s controller to execute functions by clicking the form’s button.
I need to read/write some files though, and the only way I found is by requiring the ‘fs’ module.
I also need the ‘child_process’ module to execute some bash commands.
[*] The problem is that when I use: “const fs = require(‘fs’);” some error occurs and the function stops there.
[!] I tested it with outputting data before and after the require and only the code before was executed.
[!] By requiring ‘child_process’ with the same way, the plugin won’t even be installed. The error is that ‘child_process’ module was not found (in the ‘fs’ case, the plugin is installed successfully).
Notes:
I executed the same code outside the plugin in a linux console, and it worked fine with both ‘fs’ and ‘child_process’.
I tried downloading the ‘fs’ and ‘child_process’ module in order to add them in the node_modules folder of the plugin by using npm but it is saying that those modules are moved to another module name and I need to contact them in order to get the files
[?] Why the node’s core modules are inaccessible from the plugin? I saw that kibana itself requires the ‘fs’ module in its modules and it works fine.
could you check from which files you are doing these require calls. This sounds, like you might be doing them from "front-end" code, i.e. any code that is placed within a public directory inside your plugin. This could would be executed in the browser and not in the Node Kibana server, thus not having access to any node modules.
Could you make sure, that the require statements are used inside code, that's executed on the server and not the browser (i.e. the console.log you put around these, should output to the console, where you started the server and not in your browser dev tools).
If it's in server code: are there any errors written to the console?
I tried making a custom module which requires these libraries and returns the 2 consts into the app's controller function.
If I do the actions I need to perform inside the custom module it will work?
That won't work. It would still try to import fs in the browser. You do need to create an server side API, that will write those files and execute those commands.
You can have a look e.g. at the console plugin or most other plugins, on how to create new APIs in the Kibana server. Your frontend code would now need to make AJAX requests to that API, so that the API can now execute commands and write files, and return whatever the client need to show in the browser.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.