Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Javascript - Node.js require('ttapi') not working from bookmarklet

Javascript - Node.js require('ttapi') not working from bookmarklet


I'm trying to write a bot for using alaingilbert's API (, which uses node.js. I've never written a line of javascript before, so I'm not sure what I'm getting wrong here.

Here's my code:

var container = document.body;

if(document.getElementById("ttapi")) {
var obj = document.createElement("div"); = "ttapi"; = "absolute"; = "20px"; = "20px"; = "500px"; = "100px"; = "10px"; = "#fff"; = "13px";
var auth = document.createElement("div");
    auth.innerHTML = "Auth: "+turntable.user.auth;
var userid = document.createElement("div");
    userid.innerHTML = "UserId: ";
for (var i in turntable) { if (turntable[i].roomId) { var rid = turntable[i].roomId; break; } }
var roomid = document.createElement("div");
    roomid.innerHTML = "RoomId: "+rid;
var testLine = document.createElement("div");
    testLine.innerHTML = " IM STILL WORKING";

var Bot= require('ttapi');
var AUTH = turntable.user.auth;
var USERID =;
var ROOMID = rid;   


I'm running the script from a bookmarklet while on turntable. I'm not really sure how to get good debug messages from javascript, so I'm debugging by moving container.appendChild(obj) down with each line of code. It stops displaying when the script stops working

Problem courtesy of: ZECTBynmo


It sounds like you're trying to run node.js code in the browser. If this is correct, then it won't work because require is a node-specific function. Node.js does not run in a browser; it is an alternative runtime for javascript that things like run on instead of on a browser.

If you want to write something using a bookmarklet, you will only be able to use what is available through the browser--that is, what you can access when you go to, open the javascript console and start typing things in. This generally consists of window and document, and any libraries that is using. If they're using the jquery, for example, you can access that with $.

Edit: Also, if you are using firefox look for the 'firebug' extension. If you're lucky (or use chrome), your browser (or an extension like firebug) will give you console.log which is useful for debugging.

Oh, and here's the manual: You'll want to read it.

Solution courtesy of: Joshua Holbrook


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Javascript - Node.js require('ttapi') not working from bookmarklet


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription