How to remotely inspect data with Heroku / RedisCloud / Node.js - node.js

I have RedisCloud running with Node.js on Heroku and would like to inspect data remotely, ideally using the command line in OS X. I've seen this:
How can I remotely inspect the data in my RedisCloud DBs?
but it is for Ruby and doesn't work for me. (I get redis-cli: command not found.)
I'm using the node_redis client:
https://github.com/mranney/node_redis
The requires in my server app look like this:
var express = require('express'),
app = express(),
http = require('http'),
server = http.createServer(app),
io = require('socket.io').listen(server),
redis = require('redis'),
ioredis = require('socket.io-redis'),
url = require('url'),
redisURL = url.parse(process.env.REDISCLOUD_URL),

redis-cli isn't a Ruby tool, it is a standard part of the Redis package. The easiest way of getting on your Mac is to download and build Redis from https://github.com/antirez/redis. Once you've done that, your laptop will be able to use the compiled binary.
Note that when in a bind and in need of connecting to Redis, you can also use plain telnet.

Related

How to get THREE.JS project to work with PHP not just HTML? [duplicate]

Ok I've been playing around with nodejs, expressjs and socket.io to create some applications. But now im coming to the stage where i want to take things a bit further.
I have noticed a few node apps using PHP for twitter auth on their client side. When I attempt to rename my client.html file to client.php and restart the server it throws up a blank page with this
Cannot GET /
How do would serve php files or would i do twitter auto using js?
This is my NodeJS server.js
var http = require('http'),
express = require('express');
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
app.use(express.static(__dirname + '/public'));
});
app.listen(1234);
console.log("server started on port :1234");
As already noted, node.js itself won't interpret php files for you. Available options are:
have nginx in front of node and reverse proxy all request you want to process in node from it
proxy php requests from node to php-capable server
spawn php process on each request in node
make fastcgi link to php-fastcgi using node fastcgi protocol parser
Uh, skip PHP entirely and integrate everyauth into your app.
PHP-EXPRESS should do. Just install the package and follow the docs.
https://www.npmjs.com/package/php-express

Node - Attaching to server / websockets

I am running a vue application (VUE-CLI 3) on Node. In dev mode, I run 'npm run serve' and the application is brought up and works as expected.
I would now like to add websocket code to the server.
Most examples I see have some setup code similar to:
const http = require('http');
const server = http.createServer();
const wsServer = new WebsocketServer({httpServer: server});
When I run 'npm run serve' I now am greeted with the following error message:
'http.createServer is not a function'
Is there a way to attach the websockets to the current running node server when invoked via npm run serve? In other words, can I skip the createServer call and attach it to whatever is currently running?
Well, your code should read something like this...
var express = require('express');
var app = express();
var http = require('http');
var server = http.createServer(app);
var io = require('socket.io').listen(server);
You will need to use ExpressJS on the back-end to handle messages.

Localhost not working with node.js and socket.io

I am trying to learn the basics of node.js and socket.io. I have been using this tutorial http://tutorialzine.com/2012/08/nodejs-drawing-game/
the full code for this problem can be seen in the link above.
I can create a basic web server with node.js and get it to return hello world so I am sure that's installed correctly. However upon installing these packages
npm install socket.io#0.9.10 node-static
and setting up the serverside js as instructed
var app = require('http').createServer(handler),
io = require('socket.io').listen(app),
nstatic = require('node-static');
var fileServer = new nstatic.Server('./');
app.listen(8080);
I just get this prompt in my cmd and a constantly hanging web browser, instead of the html page that is meant to be served.I think I may have messed up an install but upon looking at the list of installed packages in npm it states both socket.io and node-static are present.
The code below should be more effective?, it looks like you are missing the handler part. The response must be explicitly ended or browser requests will hang forever like you are seeing. The node-static file.serve method manages the request once you pass it down. The source for .serve is here: https://github.com/cloudhead/node-static/blob/master/lib/node-static.js#L164
var app = require('http').createServer(handler),
io = require('socket.io').listen(app),
nstatic = require('node-static');
app.listen(8080);
var file = new nstatic.Server('./');
function handler(request, response) {
request.addListener('end', function () {
file.serve(request, response);
}).resume();
}
console.log('started')
Note also that the default file to serve to responses at / is index.html.

Redis in Nodejs on Cloud9 IDE: [Error: Auth error: undefined]

Here is my code:
var express = require("express"),
app = express(),
server = require("http").createServer(app),
io = require("socket.io").listen(server),
redis = require("redis"),
env = {PORT: process.env.PORT || 8080, IP: process.env.IP || "localhost"};
client = redis.createClient(env.PORT , env.IP);
client.on("error", function(err) {
console.log(err);
});
server.listen(env.PORT);
console.log("Server started # " + env.IP + ":" + env.PORT);
After trying to run, I received the followings on the console:
Running Node Process
Your code is running at 'http://modified.address.c9.io'.
Important: use 'process.env.PORT' as the port and 'process.env.IP' as the host in your scripts!
info: socket.io started
Server started # modified.ip.address.1:8080
[Error: Auth error: undefined]
I tried establishing the connection, and it connects to the IP and PORT perfectly. However, the error [Error: Auth error: undefined] appears and stops there. I Googled the error, the supports from the IDE I used..., and surprisingly, there are only 7 links to my problems. So I think it may be a hole in my knowledge or it is not really a problem yet a thing I don't know to work it out. All I could pull out from those Google results were (I was not sure) I need to use client.auth(pass) right after creating it. But where should I find the password? When I installed it npm install redis I didn't configure anything and wasn't told to set password whatsoever. So I reach the impasse.
I use Cloud9 IDE (c9.io), and the modules used as shown in the code above.
----With best regards,
----Tim.
I've found out what was wrong.
I did install Redis, but that is a Redis library that acts like a bridge between Redis driver and NodeJS. On Cloud9, I have to manually install Redis, too.
So it would take 2 commands to actually install Redis:
Install the Redis Driver on Cloud9
nada-nix install redis
Install Redis library for NodeJS
npm install redis
Thanks for anyone who was trying to help me.
You can run the redis-server using your own config file.You can create your own config like below.
//port and ip of ur redis server
port 6371
bind 127.0.0.1
//password for this server
requirepass ucanmentionurpwd
//storing snapshots of the data
save 60 1
dbfilename dump.rdb
dir /tmp/db
//starting redis server
redis-server //ur config file location
See this link for redis configuration
https://raw.github.com/antirez/redis/2.6/redis.conf
If you mention requirepass with your password means only you need to do
client.auth('urPwd');
Otherwise no need to call the client.auth method.

Node.js restify with socket.io

Is it possible to run socket.io & restify on the same port like express & socket.io?
I did just like this but it didn't work
# server.coffee
restify = require 'restify'
socket = require 'socket.io'
server = restify.createServer()
io = socket.listen server
server.listen 1337
when I try to connect to socket.io:
GET http://localhost:1337/socket.io/socket.io.js 404 (Not Found)
As suggested here by #jtomasrl and #zacheryph, this worked for me:
var server = restify.createServer();
var io = socketio.listen(server.server); //Note server.server instead of just server
Since this is the first google hit for "restify socket.io" I'm posting a new answer. This works fine now as documented at http://restify.com/docs/home/#socketio
Apparently, using socket.io with restify is not possible yet: https://github.com/mcavage/node-restify/issues/230

Resources