⬆️ ⬇️

Zoia.js: another web framework on Node

Hello everyone, dear habrazhiteli.



Many of you have dealt with Node.js in one way or another. Probably, it makes no sense to talk about the advantages that JavaScript has and its server implementation in particular. At the moment I am doing a lot of things on JS, from simple console scripts to API, services and sites. The modern standard EcmaScript has brought significant changes to the language: it not only fixed some of the ancient “jambs” of JS, but also added new features, allowing, in particular, to get rid of the Callback Hell beautifully.



When I once again faced the task of deploying a simple website consisting of several dozen pages, I wanted to do this with the help of some lightweight but modern CMS based on Node. Having assessed the situation , I realized that there is nothing suitable so far. My old and kind Taracot turned out to be too heavy for this task, besides, it does not work with modern versions of Node and is overloaded with functionality.



What did I want to get in the end?

')



Automatic update system

A simple module for creating and editing content with easy uploading images to the server



Zoia.js



I worked in my spare time and solely for the sake of pleasure, so the project dragged on a bit, but from the first commit in late May to mid-October 2017, we managed to do a lot on the above points:





image



License - MIT .



Express.js is used as the base framework, MongoDB is used as the base framework, Mozilla's Nunjucks is the template engine, and UIkit is used for the UI.



Why the Web Framework, and not just a CMS? First of all, because it is possible to make an API based on the system, using, for example, only the possibilities related to authorization. That is, from Zoia, you can safely "throw out" modules associated with the display of content for the user, and return only JSON / XML.



Dynamic tables and forms



For the dynamic display of data in tabular form, I wrote a jQuery plugin zoiaTable . It allows you to turn any HTML table into a “dynamic” one, with the ability to filter data, paginate and sort. How it looks “live” can be found here .



Convenient form building is another task for which I wrote another plugin: zoiaFormBuilder . It has two main tasks: dynamic construction of forms with the possibility of data serialization / deserialization and data validation according to specified rules.



Both plugins are licensed under the MIT license and can be used separately from Zoia, although at the moment I only need them there. The display is not tied to a specific framework (you can set the desired HTML and styles in the call parameters), the default is UIkit.



What else is implemented at the moment?



First of all, an accessible user and group management system. In the long term, this will make it possible to make a distinction of rights for modules and their individual components (for example, a certain group can edit pages only in a specific folder). At the moment there is one system group - admin, which allows users to log in to the backend.



The user registration system is made fairly standard - with validation by e-mail. It is possible to recover a forgotten password (also via e-mail). In the future, it will be necessary to tighten the authorization through various social services (by Oauth), two-factor authorization (for example, via Google Authenticator or SMS), and also to make a simple personal account. What of this is necessary in a system that positions itself as “lightweight” is a separate question.



Captcha samopisnaya does not use third-party libraries like GraphicMagick, instead JIMP is used - a library that does not use external dependencies.



The Content Editor uses CKEditor as the WISIWYG editor. It is possible to insert bread crumbs (breadcrumbs) into the pages. Also a simple browser was written with the ability to upload files and automatically create thumbnails:







He can create folders, copy-move files, in general, he has all the basic functionality available.



The navigation module (Navigation) allows you to create multi-level navigation menus for the site. Work with navigation is carried out in the form of a tree in which you can create, edit and drag elements.



The system of automatic updates allows you to download a new version of the system and watch the list of changes.



How to install Zoia on your server?



You will need the installed Node 7+ and MongoDB. I am developing under Windows, so it works there too, but in production, of course, it’s better to use a Linux-based system. To install Zoia, you need to install nginx and mongo packages in the system, then execute the following commands:



mkdir /var/www/zoia && chdir /var/www/zoia

wget -q -O - https://xtremespb.imtqy.com/zoia/zoia_download | bash

npm run config && npm run install && npm run webserver




You can also install everything through Docker:



docker pull mongo:latest

docker pull xtremespb/zoia:latest

docker run -d --name mongo mongo

docker run -p 3000:3000 -d --name zoia --link=mongo:mongo xtremespb/zoia

docker exec -it zoia node /usr/local/zoia/bin/install.js




More information about the installation can be read in the documentation .



What will be implemented



At the moment, the framework is in the beta state (I think it will be in such a state for quite a long time). As I wrote above, I want to modify the authorization module (Auth) to a certain stage in order to make two-factor authentication and Oauth - but this is not yet accurate.



Also, apart from the basic system, I want to make a module for blogging (personal or collective), as well as a simple module of an online store.



Documentation - I'm still working on it. In general, I work on everything, including architecture, design, development and testing, and there is very little time. That is why there is no translation into Russian (and other languages) yet, but I will be glad if someone can help me with this. Also I will be glad to all developers who want to work together on a project - the code is open .



For a long time did not publish anything on Habré.

If you did something wrong, please write in a personal.



UPD: Thank you all for the comments! Since the publication of the article, I received a large number of individual comments, and over the past weekend I implemented the following changes: 1) the system configuration files are now in JSON format and excluded from the versioning system; 2) the system version is stored directly in package.json; 3) the updated Docker image is based on node: slim and uses only one RUN command; 4) the updated installer does not require root and does not install system packages for the user.

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



All Articles