N
N
Nikita Gusakov2013-09-12 18:18:13
Twig
Nikita Gusakov, 2013-09-12 18:18:13

Tip for a newbie in node.js

Framework I looked at the learn.javascript.ru/nodejs-screencast
course , perhaps the author has not yet told everything to the end, but I understand that express has a micro-framework architecture (in the php world anyway). That is controllers lie in the daddy, models in the daddy, also. Is it possible to make modularity like in symphony, where each module is responsible for its own task, it has its own controllers, its own models, and so on. require/dic Do I understand correctly that require in node.js is a kind of DIc? That is, like in my test project - there is a service folder, and there is a logger and a connection to the database. There I plan to configure the router and other dependencies. template engine


I really like twig, it's good that there is twig.js. As far as I understand, I am writing a server on a node, and not just an application, so I can store data between requests without middle ground. Does twigjs cache data in this way, or in some other way, and can it be pulled out to be sent to the client? Perhaps you will advise another js template engine (not ejs and not jade). With modularity like a twig.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin Kitmanov, 2013-09-12
@k12th

1) You can. Google express sub apps.
2) Modules are modules, they have nothing to do with IoC. There is no such thing in PHP, hence the misunderstanding, apparently. Part of the module mechanism can help create IoC/DI.
3) On the node, you are writing the application, albeit with a built-in server. The data between requests is naturally stored in memory, stupidly in a variable. Naturally, when the application is restarted, such data will be lost.
It is doubtful that the template engine cached the data. They usually cache compiled templates, not passed data.

T
Timur Shemsedinov, 2013-09-13
@MarcusAurelius

Framework
Look towards Impress , for PHP-shnik it will be more natural. All urls are mapped to the file system, templates and handlers are redefined. By creating directories, routing is done to pages and to API handlers. You can change the handler code without restarting the application, simply by editing the file on disk. It is loaded into memory and cached, the same thing happens with templates. All without restart, works in multi-threaded (cluster) mode. It already has a dozen projects running under load. Here is an article on Habré about Impress (written at the time when it was still a prototype): Prototype of a totalitarian framework for node.js
require/dic
Modularity in Impress is specific, handlers are divided into separate files, but models and controllers can be written as libraries in such a pattern as described here: JavaScript module patterns in Impress for node.js and browsers
Template engine
Impress has a very simple template engine, perhaps , it is not as functional, but it is very productive, unlike, for example, EJS, which is made simply illiterately, because it uses synchronous reading of templates from disk. For a node, synchronous operations are generally knocked out of the concept and destroy all advantages.
If anything, please contact me, this is the development of my company, everything is open source, licensed by RUMI. Gradually we are doing the documentation, and there are plenty of examples, the admin panel for databases, laid out in the source along with Impress in one package, can serve as good examples.

O
OnYourLips, 2013-09-13
@OnYourLips

Accordingly, I can store data between requests without middle ground.
You can store it, but different node processes will have different data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question