Web App Framework (HTTP, WebSockets, MVC, DI)
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,
- 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.
Darkside.js is distributed via NPM.
npm install darkside
Your bootstrapping file should look somewhat like this:
var darkside = require'darkside';var app = darksidecreate__dirname;approutersetRouteDeclaration'./routes.declaration';appservicessetServiceDeclaration'./services.declaration';apprunprocessenv'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.MongoDBServicename = 'blog'server = 'mongodb://user:*****@localhost:27017'@repositoriesposts
Controller files are located in the
controllers subdirectory of the specified application directory (
__dirname in the example above). They are grouped by namespaces.
A controller that simply retrieves
Post entities from the database and populates its views with them would look like this:
var darkside = require'darkside';vardarksidebasedarksideViewController this;this$posts = posts;;darksideinheritsPostController darksideViewController;'posts' ; // dependenciesPostControllerprototype'index' =this$postsallif err return this$responseend500;thisview'posts' = posts;thisrender;this;;PostControllerprototype'show' =this$postsoneparams'id'if err return this$responseend500;thisview'post' = post;thisrender;this;;moduleexports = PostController;
Note: The way inheritance and DI are combined might be subjected to a change in the future.
The templating engine used by Darkside.js is ECO (Embedded CoffeeScript) because of its lightweight syntax.
Template files are grouped by namespaces and controllers:
By default, a layout and a content templates are bound to
Content templates are inserted into layout ones as the
<!-- @layout.eco: --><%= @component 'content' %>
<!-- post/index.eco: -->Posts<% for post in @posts: %><%= post.title %><%- post.content %><% end %>