📜 ⬆️ ⬇️

The prototype of the totalitarian framework for node.js

for recycling If you are programming on node.js , but are tired of writing routing requests in code, you do not have a prejudice against using global variables for business purposes and you agree that excessive freedom is destructive for the masses, then the totalitarian weekend group prepared for you a prototype of an alternative platform for web application development . I warn you that the totalitarian style does not involve embedding the framework into an application through require, but rather embedding your application into the framework structure, where application code fragments will deal with additional restrictions and imposed code and data structures at every step. About the fact that “less-than-expert” will be able to develop high-performance systems, according to the developers of the node - well, here you yourself understand what these systems will be, especially asynchronous, with lost callbacks and memory leaks at every step. In terms of protection from the fool, this prototype does not deliver miracles. And of course, I expect a lot of constructive criticism from you, because the prototype is crude, although it has gathered a lot of conceptual developments of our team over the past decade. Even the name Impress appeared just two days ago and, yes, this is the most difficult question.

Features and Features



Plans for the near future



Installation and Setup


1. Install from npm ( https://npmjs.org/package/impress )
$ npm install impress 

2. Copy the project template - the contents of the / node_modules / impress / examples / copyContentToProjectFolder directory are transferred to the project directory (server.js, setup.js, config.js and the sites directory).

3. Nasraivaem file config.js go through the sections of the config:
databases - databases that will be automatically opened at startup and the listed collections will be available placed in this way: db.dbName.collectionName.find (...). Configuration example:
 dbName: { url: "mongodb://localhost:27017/dbName", collections: ["collname1", "collname2"] } 

session - the name of the length and character set to generate a session cookie, the name of the database for permanent storage of sessions.
cluster - setting up an instantiation strategy (multi-threaded type).
servers - named servers (interface / port), for each hosts field - an array of named hosts that need to be sent from this server, static - an array of file masks for static rendering, for example ["/ css / *", "/ images / *" , "/ js / *", "/favicon.ico", "/index.html"].
hosts - named hosts (virtual hosts), you can use masks for naming, for example "* .myhost.com".
routes - Named Request Forwarding Routes.

4. To initialize the data structures in MongoDB, run node setup.js and click “y”.
')
5. In the server.js file, we can also write our own additional code for initialization:
 require('impress'); impress.init(function() { //    }); 

6. And start the server
 $ node server.js 

See examples


1. Templates: when the server is running, open http: // localhost
and look at the template here: /sites/localhost/html.template
We look at the application, click "Create account", "Sign In"

2. Example of redefining the “left.template” template with logic inheritance, open http: // localhost / override
and look at the template here: /sites/localhost/override/left.template
base template here: /sites/localhost/html.template
server logic handler here: /sites/localhost/request.js
3. An example of an API method with a JSON response is: http: //localhost/api/examples/methodName.json
and code here /sites/localhost/api/examples/methodName.json/get.js
4. An example of starting an anonymous session : http: //localhost/api/auth/anonymousSession.json
and code respectively: /sites/localhost/api/auth/anonymousSession.json/get.js
5. Example of a POST request : with an effort of thought, we do a POST at localhost / api / auth / regvalidation.json with the “Email” parameter
and code: /sites/localhost/api/auth/regvalidation.json/post.js
6. Example of access to the MongoDB database :: http: //localhost/api/examples/getUsers.json
and the code is here: /sites/localhost/api/examples/getUsers.json/get.js
or here it is right:
 module.exports = function(req, res, callback) { res.context.data = []; db.impress.users.find({}).toArray(function(err, nodes) { res.context.data = nodes; callback(); }); } 

Links


On Github: https://github.com/tshemsedinov/impress
In npm: https://npmjs.org/package/impress

UPD: Very rough tests on the Hetzner EX4 hosting (Intel Core i7-2600 Quad-Core, 16 GB DDR3 RAM) gave 22`572 requests per second with a template of 5 files and a simple request to the database.

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


All Articles