npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

symfony-essentials

v0.1.1

Published

A module that implements some features of symfony: dependency-injection (container) / router / controller

Readme

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":

{
    "parameters": {
        "port": "8080"
    },
    "services": {
        "todo": {
            "class": "/src/Service/ToDoService",
            "arguments": ["@request", "!port"]
        },
        "chat": {
            "class": "/src/Service/ChatService",
            "factory": ["socket.io"]
        }
    }
}

Example of a service:

// /src/Service/ToDoService.js
module.exports = function(request, port) {
    this.request = request;
    this.port = port;
    this.todoList = (request.session.todoList || []);

    this.addNote = function(note) {
        this.todoList.push(note);
        this.save();
    }

    this.removeNote = function(index) {
        this.todoList.splice(index, 1);
        this.save();
    }

    this.save = function() {
        this.request.session.todoList = this.todoList;
    }
}

How to use:

// /index.js
var container = require("symfony-essentials");

var todoService = container.get('todo'); // get todo service defined above
var app = container.get('app'); // get express application
var path = container.get('path'); // equivalent to require('path')
var port = container.getParameter('port'); // get parameter port

container.listen(port);

Router / Controller

Controller in symfony Router in symfony

Controllers need to be defined in /src/Controller Folder. Example of a controller:

// src/Controller/DefaultController.js
module.exports = function() {
    this.indexAction = function (req, res) {
        var todoService = this.get('todo');

        res.render('index.twig', {
           list: todoService.todoList
        });
    }
    this.addNoteAction = function (req, res) {
        if (req.body && req.body.note && req.body.note != "") {
            this.get('todo').addNote(req.body.note);
        }
        this.redirect('homepage');
    }
    this.removeNoteAction = function (req, res, id) {
        this.get('todo').removeNote(id);
        this.redirect('homepage');
    }
}

Example of routing.json

{
    "homepage": {
        "path": "/",
        "defaults": {"_controller": "Default:index" }
    },
    "add_note": {
        "path": "/addNote",
        "defaults": { "_controller": "Default:addNote"},
        "methods": ["POST"]
    },
    "remove_note": {
        "path": "/removeNote/:id",
        "defaults": { "_controller": "Default:removeNote"}
    },
    "chat": {
        "path": "/chat",
        "defaults": { "_controller": "Default:chat"}
    }
}

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:

{
    "parameters": {
    },
    "services": {
        "chat": {
            "class": "/src/Service/ChatService",
            "factory": ["socket.io", "chat"],
            "autoload": true
        }
    }
}

Implementation of the service:

// /src/Service/ChatService.js
module.exports = function() {
    this.onConnection = function () {
        this.emit('start', 'Bonjour !');
    }
    this.onLogin = function(data) {
        this.set('login', data);
    }
    this.onMessage = function(data) {
        this.emitAll('message', {"user": this.get('login'), "message": data});
    }
}

This is equivalent of:

// /index.js
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);

server.listen(80);

io.of('chat').on('connection', function (socket) {
    socket.emit('start', 'Bonjour !');
    socket.on('login', function(data) {
        socket.login = data;
    })
    socket.on('message', function (data) {
        io.emit('message', {"user": this.get('login'), "message": data});
    });
});