M
M
microf2015-10-05 20:31:01
Node.js
microf, 2015-10-05 20:31:01

Is there a "service"?

Sorry if the question is stupid.
I'm learning angular, and at the same time, I'm looking at node.js. In angular, there is the concept of a service for transferring data between controllers, and, in general, by all entities. Is there such a thing in nodejs?
Let me explain (I'll try). I have a bilingual application, I store title : { ru : 'Title', en : 'title'} in the database and I want the server controller to pull either ru or en, depending on the existing language. Is it possible to create some kind of service in node, so that in each controller it is not necessary to find out "what language does the user currently have?". Or I connect some kind of c file to each controller

exports.language = function (req, res) { 
var currentLanguage = .... }
,
and in the controller (where I make a request to the database) I do something like
var language = require('файл с определением языка')

well, then I somehow build a query to the database "pull everything with the locale language" (I don't know how to do the query yet) Does
it work like that? And how to force to pull out new values ​​from base if the existing language changes?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-10-05
Protko @Fesor

In angular there is a concept of a service for passing data between controllers

It's not for that, it's for stuffing the whole business logic there. In general, these are just some objects that do something. Let's say filters can also be used as services, as well as controllers.
what you are looking for is called "middleware".
ps read about design patterns, solid, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question