Make the variables in Node module usable by jQuery, Ember, etc

I'm really new to the world of backend, and I'm trying to have the variables that I made within a Node module (called app.js) accessible by other ordinary JavaScript modules. The data within the said variables is from MongoDB, if that matters.

So far I can only res.send() the data as boring plain text on the page. I want to be able to manipulate this data for other purposes (such as making a table). So how can I pass these variables to JavaScript, and so I can display them properly in HTML?

I hope I understand your question correctly.

Since you tagged restify, I am assuming you are just sending out JSON in your res.send() stuff?

With that, you would need to serve files to your users that had AJAX calls to get the JSON data and then manipulate it however you want on your frontend side.

I'd suggest trying with something like backbone or angular. With these frontend JS frameworks, you can tie your frontend to your database.

Otherwise, you could also look into express or something similar in which you can manipulate the data and do whatever you need to do, and then serve a template containing that data.

I'm just throwing a few ideas out there, because it's really up to you what tech you decide to use (there's tons of stuff out there). You could even just do pure JS AJAX requests to your server to get the data, but that would get tedious if you're building a webapp on this sort of system.

You can use res.render to pass the data to a rendered web page, with express and jade it looks like this:

res.render('yourView', {
    data: yourVariable
}

Res.render will go where you have your res.send. Which should either be with your app initialization (app.js) or in an external file like (router.js), that is then fed to your app.

Then in the template used as the web page you can call it like this:

#{data}

Or you can make a list like this (if you are using jade)

each data in rows
    li= data

Hope this is what you meant, and helps :D.

An example of what app.js might look like now:

var express = require('express');
var http = require('http');
var bodyParser = require('body-parser');
var methodOverride= require('method-override');
var routes = require('./routes')(app);
var path = require('path'); 
var app = express();

app.configure(function() {
    app.set('port', process.env.PORT || 3000);
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
    app.use(bodyParser.urlencoded({extended: true}))
    app.use(bodyParser.json())
    app.use(methodOverride());
    app.use(express.static(path.join(__dirname, 'public')));
})

app.get('/', function(req, res){
    res.render('home', {
        title: "Welcome to an example site"
    });
});

http.createServer(app).listen(('3000'), function(){
    console.log('Server Online');
});