⬆️ ⬇️

We make admin panel for MySQL and MongoDB on Node.js

We want "phpMyAdmin" (read web GUI) for node



The lack of universal web-based interfaces for managing common DBMS makes it somewhat difficult to learn Node.js , and deploying another web server and another language with infrastructure alongside, oh, I don’t want to. It is inconvenient and security considerations to open ports and manage databases by connecting from another server or from your work computer. Therefore, we decided to include such a tool in the platform for web applications Impress , which was announced , which I wrote a little about and which is available in open source for general benefit . The idea is this: to implement a simple and convenient unified interface for DBMS, which are most often used in conjunction with Node.js, take care of quick deployment (just copy the folder) and independence from the environment. In the beta version, MySQL , MongoDB are already supported, and soon the queue will reach PostgreSQL and Oracle .



DBMI features



For all database operations, scaffolding is used, i.e. building interfaces, queries and all data processing operations based on the dynamic acquisition of metadata about the database structure or introspection of the DBMS structures. The interface is shown below in the picture. The tree is three-level, the first level is the connections to the database (they are, of course, of the two types), the second level is the databases, the third level is the collections (for Mongo) and the tables (for MySQL). On the tree nodes, you can call the context menu with the right mouse button.







The functionality is as follows:



Installation and Setup



The complete setup procedure is as follows (this is due to security, but in most cases, it is significantly reduced):

1. Create a project directory and install Impress from the npm repository in it.

$ npm install impress 


2. Copy from the folder / node_modules / impress / examples / copyContentToProjectFolder all the content in the root directory of the project.

3. In the file config.js we set the databases we need (connecting them to) in the “databases” section.

4. In the file /sites/localhost/dbmi/access.js we find the access settings

 module.exports = { guests: true, //       logged: true, //       http: true, //     http https: true, //     https groups: [] //     ( ) } 


5. In order to close the admin panel with a password, you need to create a user base using the “node setup.js” command. And then start the "node server.js" system. Go to 127.0.0.1 and register (“Create account” at the top right). After that, you can close the registration option by adding the access.js file to /sites/localhost/api/auth/register.json and setting guests = false in it.

6. If you want to go to the database via HTTPS, then put your server.key and server.cer files in the root of the project, as well as adjust the servers.www.protocol = "https" parameter in config.js.

7. Well, you can enter via 127.0.0.1/dbmi or 127.0.0.1 and select the “DB Management Interface” item in the menu on the left.

')

DBMI Development Plans



The entire DBMI module is now 70kb, half of which consists of css and html, about a quarter - server js, and another quarter - client. I think that it is not so much to understand the code if you want to correct or add something. The small size is also because the Impress platform (of our own production) produces most of the infrastructure work, like URL routing, template processing, a huge number of database support functions, especially with MySQL ( data access methods , methods introspection , query generation methods , etc.). What do we plan to finish in the near future:



 require('impress'); var schemaCore = require('./schemas/impress.core.schema.js'), schemaCMS = require('./schemas/impress.cms.schema.js'); impress.init(function() { console.log(db.schema.mysql.generateScript(schemaCore, true).script); console.log(db.schema.mysql.generateScript(schemaCMS, true).script); }); 




It moves fast, but you need a thing such that everyone needs and it is desirable - even faster. So, join the testing and refinement, we will be glad to your participation.



UPD: Added the ability to execute SQL code entered in the editor (on the “Command” tab) and output the results and execution errors to the log (on the “Logs” tab).

Source: https://habr.com/ru/post/192302/



All Articles