symfony-essentials
Symfony developer, when i begin nodejs, I wanted to implement some features of symfony.
Dependancy injection (container)
Dependancy injection in symfony Dependancy injection work with a configuration file named "services.json" to be added to the root of your project.
Example of "services.json":
Example of a service:
// /src/Service/ToDoService.jsmodule { thisrequest = request; thisport = port; thistodoList = requestsessiontodoList || ; this { thistodoList; this; } this { thistodoList; this; } this { thisrequestsessiontodoList = thistodoList; }}
How to use:
// /index.jsvar container = ; var todoService = container; // get todo service defined abovevar app = container; // get express applicationvar path = container; // equivalent to require('path')var port = container; // get parameter port container;
Router / Controller
Controller in symfony Router in symfony
Controllers need to be defined in /src/Controller Folder. Example of a controller:
// src/Controller/DefaultController.jsmodule { this { var todoService = this; res; } this { if reqbody && reqbodynote && reqbodynote != "" this; this; } this { this; this; }}
Example of routing.json
Easier implementation of socket
Socket is important in node, this module implement a clearer and easier way to use socket. Example of a chat implementation:
Definition of the service in services.json:
Implementation of the service:
// /src/Service/ChatService.jsmodule { this { this; } this { this; } this { this; }}
This is equivalent of:
// /index.jsvar app = ;var server = ;var io = server; server; io;