Node.js - Global variable not found on client side

I am trying to implement socket.io-stream and in my server side file it works fine, but client side:

This is the top of the clientide, where the file stops loading, in ss.createStream () because "ss" was not found.

var socket = io.connect();
var username = null;
var userarray = null;
var stream = ss.createStream();
var filename="profile.jpg";

ss(socket).emit('profile-image', stream, {name: filename});
fs.createReadStream(filename).pipe(stream);

      

It always says that ss is not defined even though I added it to the head html.
This is the top of the jade pattern where scripts are defined in the head.

doctype html
html
  head
    script(src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js")
    script(src="/socket.io/socket.io.js", type="text/javascript")
    script(src="script.js", type="text/javascript")
    script(src="http://chaterix.com/node_modules/socket.io-stream/socket.io-stream.js")
    script(src="char.js", type="text/javascript")

      

My structure looks like this:

root
-public
--script.js (client side)
-node_modules
--socket.io-stream
---socket.io-stream.js (the file I am trying to use)
server.js (server side)

      

I also tried using browsify as the developer wrote:

$ npm install browserify -g
$ cd node_modules/socket.io-stream
$ browserify index.js -s ss > socket.io-stream.js

      

but that didn't help either.

socket.io-stream.js: https://github.com/nkzawa/socket.io-stream/blob/master/socket.io-stream.js

and here is the top of server.js (server side)

var http = require('http'),

    express = require('express'),

    app = express(),

    jade = require('jade'),

    server = http.createServer(app),

    bodyParser = require('body-parser');

var io = require('socket.io');

var escape = require('escape-html');

io = io.listen(server);
var fs = require("fs");
var ss = require('socket.io-stream');
var path = require('path');
var Entities = require('html-entities').AllHtmlEntities;

entities = new Entities();
server.listen(3000);

      

+3


source to share


1 answer


move socket.io-stream.js file to your public / js folder and include this js file in your EJS or any client side view file



0


source







All Articles