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 🙏

© 2024 – Pkg Stats / Ryan Hefner

darkside

v1.2.6-rc.2

Published

Web App Framework (HTTP, WebSockets, MVC, DI)

Downloads

131

Readme

Darkside.js

Darkside.js aims to be a lightweight Node.js (server-side JavaScript) framework for building larger web apps.

It leverages the MVC architecture and the dependency injection design pattern.

Darkside.js features most of the components you would expect from a server-side framework:

  • an HTTP server
  • a WebSocket server (via socket.io)
  • a request router,
  • controllers
  • a model system (entities and repositories) connected to a MongoDB service
  • a templating engine

Disclaimer: This is originally a high school graduation project (2012) of Jan Kuča from Prague, Czech Republic. This, however, does not mean that the development ended together with his graduation. The project is kept alive and will remain here on Github.

Installation

Darkside.js is distributed via NPM.

npm install darkside

Getting started

Your bootstrapping file should look somewhat like this:

var darkside = require('darkside');
var app = darkside.create(__dirname);

app.router.setRouteDeclaration('./routes.declaration');
app.services.setServiceDeclaration('./services.declaration');

app.run(process.env['PORT'] || 5000);

You need to declare your routes and your services:

# routes.declaration:

www
  / = 'front:post:index'
  /posts/:id = 'front:post:show'
  POST /posts = 'front:post:create-post'

m
  / = 'mobile:post:index'
# services.declaration:

database
  @ = darkside.MongoDBService
  name = 'blog'
  server = 'mongodb://user:*****@localhost:27017'

@repositories
  posts

Controllers

Controller files are located in the controllers subdirectory of the specified application directory (__dirname in the example above). They are grouped by namespaces.

controllers/
  front/
    PostController.js
  mobile/
    PostController.js

A controller that simply retrieves Post entities from the database and populates its views with them would look like this:

var darkside = require('darkside');

var PostController = function (posts) {
  darkside.base(darkside.ViewController, this);

  this.$posts = posts;
};

darkside.inherits(PostController, darkside.ViewController);
PostController.prototype.$deps = [ 'posts' ]; // dependencies

PostController.prototype['index'] = function () {
  this.$posts.all(function (err, posts) {
    if (err) return this.$response.end(500);

    this.view['posts'] = posts;
    this.render();
  }, this);
};

PostController.prototype['show'] = function (params) {
  this.$posts.one(params['id'], function (err, post) {
    if (err) return this.$response.end(500);

    this.view['post'] = post;
    this.render();
  }, this);
};

module.exports = PostController;

Note: The way inheritance and DI are combined might be subjected to a change in the future.

Views

The templating engine used by Darkside.js is ECO (Embedded CoffeeScript) because of its lightweight syntax.

Template files are grouped by namespaces and controllers:

views/
  front/
    post/
      index.eco
      show.eco
    @layout.eco
  mobile/
    post/
      index.eco
    @layout.eco

By default, a layout and a content templates are bound to ViewController instances.

Content templates are inserted into layout ones as the content component.

<!-- @layout.eco: -->
<!DOCTYPE html>
<meta charset="UTF-8">

<body>
<%= @component 'content' %>
<!-- post/index.eco: -->
<h1>Posts</h1>

<% for post in @posts: %>
<h2><%= post.title %></h2>
<%- post.content %>
<% end %>