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

dojo-express

v1.0.0

Published

A Node.js Express based server with Socket.io support. It is based on dojo/node.

Downloads

4

Readme

dojoexpress

A Node.js Express based server with Socket.io support. It is based on dojo/node, and supports RESTful services.

OK so I was looking for a way to write client and server side code in the same language. With Node.js and Express, I was able to write client and server side Javascript - step 1 check.

One thing was still bothering me though. I love the AMD style package structure that Dojo has implemented on the client, and I wanted to write the same code on the server side. Amazingly I found the following https://dojotoolkit.org/reference-guide/1.9/dojo/node.html - step 2 check.

Now I had the building blocks for dojoexpress! Let's explore the project structure.

  1. shared - This folder is accessible to both server and client side code. Think of validation logic shared between client and sever - pretty cool stuff!
  2. frontend - This folder is only accessible to HTML clients (e.g. browser). Think of it as your WebContent folder in a traditional web app
  3. backend - This folder is accessible only on the server. Think of it as your backend.
  4. js-lib - Add other js packages here. For example, dijit, dojox etc. The dojo package in found under node_modules. This folder is accessible to client and server.
  5. app.js - bootstraps the app. This file sets up the dojo/node environment and starts an Express server with socket.io support on port 3434

One thing that a backend needs is the ability to host RESTful services. In a previous life I worked a lot with Java EE servers. I assume that many of you have also come from that not so distant past, and are familiar with Apache Wink. If not, no biggy. All you need to know is that you define RESTful resources like so (see backend/rest/Message.js):

require(["dojo/_base/declare","backend/global"],function(declare,global){
	
	var path = "/rest/message";
	var app = global.app;
			
	app.get(path,function(req,resp){
		resp.json({name : "chris",last: "Felix"});
	});
	
	app.get(path + "/:id",function(req,resp){
		
		resp.json({name : "chris",last: "Felix",id: req.params.id});
	});
});

The above should look familiar if you work with Express. "backend/global" contains a pointer to the express server in "global.app". See backend/server.js, where you have access to socket.io and the node sever itself:

global.app = app;
global.server = server;
global.io = io;

The above code is cool, because you are able to split up your RESTful services (e.g. Express paths) into AMD modules. Think about it, you can easily create a streaming socket.io version of any of your services as well through the use of global.io.

Finally, like Apache Wink, you need to register your resources to be loaded on server startup. To do this, you add the path to backend/rest/Resources.js. For example:

require([
"backend/rest/Message",   
"backend/rest/User"
]);

So by now you probably want to fire things up for a test spin. To do this:

  1. Run node app.js
  2. Go to http://localhost:3434
  3. You will see Hello World! displayed. This is coming from frontend/index.html. Congrats, you have tested file serving!
  4. Go to http://localhost:3434/rest/message to test the GET message RESTful service. You will see:
{
  "name": "chris",
  "last": "Felix"
}

Well that's about it. Happy hacking!

Licensing

This project is distributed by the Dojo Foundation and licensed under the "New" BSD License. All contributions require a Dojo Foundation CLA.