Noodles Practicing Medicine
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


    DJS makes media-sharing sites easy to make!

    Check out the github

    Install from npm

    npm install djs or npm install djs -g for a global installation.

    DJS is a Node.JS module built on top of Now and MongoDB.

    Public API

        var server = express.createServer(...)
        var dj = require('djs')

    Note: Any arguments with * are optional

    Bare Bones Server Side Functionality

    now.SbroadcastMedia(mId, *roomId, callback)

    By default it tells all the clients to display whatever media is indicated by mId. Supplying the roomId will only display the media to users in that particular room. You must search for the mId you want using SfindMedia. The callback expects an argument mediainfo, which is a JSON object of this form. The callback has to be in the now space.

        path: path_to_media
        tags: [array, of, tags]
        metadata: JSON of your choice
    now.SfindMedia(searchQuery, callback)

    Crawls the database for media with the searchQuery as part of the tag and passes the result to the callback function as an array of JSON objects of this form:

        path: path_to_media
        tags: [array, of, tags]
        metadata: JSON of your choice
    now.SaddMedia(path, tags, metadata)

    Adds the media to the database. path is just the path to the media in question; tags is an array of strings. Metadata is a JSON object of your choice!!!


    Adds the user who calls this function to the room. If the room didn't exist before you made this call, you will create it.


    By default, has the user who calls this function leave all the rooms, including the everyone namespace (i.e. a logout). When called with a roomId as an argument, has the user leave just that room.

    now.Sapply(functionName, *args, *roomId)

    By default, applies the callback function on all members of the everyone group, i.e. everybody who is on the server. Providing the optional roomId argument causes the callback to only be applied for members in the room. Note that the callback function must be in the now pocketspace.

    Groups Server Side Functionality


    If you wish to use our groups functionality then you must let us know about the users in your system. Call this when you add a user to your own DB.


    Call this when you remove a user from your database.

    now.SloginUser(uId, *callback, *args)

    Call this when a user logs in to your application. This will put him back into all the groups that he was subscribed to. Optionally, you can have a callback be called after a user is logged out. Note that if you wish to provide arguments they must be an array of arguments to your callback. Also note that your callback function must be in the pocketspace.

    The reason the callback is necessary is that login performs a database operation and so if you were to call Sapply on any group the user is logged in, the user won't receive the function since the user won't be added to the group for a while as database operations are expensive.


    Call this when a user logs out of your application. This will remove him from the groups that he was subscribed to but we will remember to put him back in those groups when he logs back in.

    now.subscribeToGroup(uId, groupId)

    Subscribes a user to a group, and adds him to the group.

    now.unsubscribeToGroup(uId, groupId)

    Unsubscribes a user from a group, and removes him from the group.

    Keep in mind that these are different from NowJS groups because these groups will persist beyond client log-in and log-out.

    Client Side Initialization

    1. Include d.js on the client side.
    2. Call initialize with a JSON object of this type:
        playback: playback(mediaInfo)
    playback is your own provided function that takes mediaInfo as an argument. mediaInfo is of this form:
        path: path_to_media
        tags: [array, of, tags]
        metadata: JSON of your choice

    Quickest Start Guide

    1. Include djs server side.
    2. Initialize the client stuff.
    3. Be super productive.


    Q: Did someone actually accidentally delete the entire codebase?

    A: No, he actually only deleted half of it.

    Q: What's up with the strange naming scheme? I don't like the C's and S's in front of your function names.

    A: It's because we've had trouble in the past writing code that utilized NowJS. Since it blurred the client server borders, we often got confused about whether functions were server-side or client-side, so to save us (and hopefully you!) from headaches we decided to do this.

    Q: What's the difference between rooms and groups?

    A: Rooms don't persist. If the server goes down, or the client disconnects, the client won't return to rooms they were connected to. Groups will persist.

    Q: What's up with your strange numbering scheme? Why does it start at 0.0.2?

    A: 0.0.0 was us claiming "djs" as a unique package name and 0.0.1 was us publishing something broken accidentally.

    Further Information

    Rainbow Dash is the best pony <3




    npm i djs

    Downloadslast 7 days







    last publish


    • avatar