0

I have 3 files :

  1. server.js containing node.js server (Using WebSocket-Node)
  2. client.js containing websocket code
  3. frontend.html containing the html content includes the client.js file.

package.json :

{
  "name": "kapp",
  "version": "1.0.0",
  "description": "Lightweight peer to peer",
  "main": "frontend.html",
  "scripts": {
    "test": "node server.js"
  },
  "engines": {
    "node": "0.10.x"
  },
  "author": "Kaustav Ray",
  "license": "MIT",
  "dependencies": {
    "websocket": "^1.0.19"
  }
}

server.js

var WebSocketServer = require('websocket').server;
var http = require('http');

var server = http.createServer(function(request, response) {

});
server.listen(1337, function() { });


wsServer = new WebSocketServer({
    httpServer: server
});


wsServer.on('request', function(request) {
    var connection = request.accept(null, request.origin);


    connection.on('message', function(message) {
        if (message.type === 'utf8') {

        }
    });

    connection.on('close', function(connection) {

    });
});

client.js

$(function () {

    window.WebSocket = window.WebSocket || window.MozWebSocket;

    var connection = new WebSocket('ws://127.0.0.1:1337');

    connection.onopen = function () {

    };

    connection.onerror = function (error) {

    };

    connection.onmessage = function (message) {

        try {
            var json = JSON.parse(message.data);
        } catch (e) {
            console.log('This doesn\'t look like a valid JSON: ', message.data);
            return;
        }
        // handle incoming message
    };
});

Local Folder Structure:

  1. .git
  2. node_modules // containing websocket
  3. client.js
  4. frontend.html
  5. server.js
  6. package.json

But somehow my application is not running and showing application error !

I want to first start the nodejs server and open frontend.html.

As I am starting with nodejs and heroku for first time cannot understand the exact problem !

  1. Is there a problem in routing or other things are causing this error ?
  2. Is express.js mandatory for routing ?
2
  • Could you show us the code in server.js? Commented Jul 19, 2015 at 10:44
  • I have pasted the basical skelleton of server and client + have updated the package.json and it is working fine in local machine but facing problems in heroku ! Commented Jul 19, 2015 at 11:06

1 Answer 1

1

Heroku requires that your either provide a Procfile, which is a simple file that tells Heroku how to actually start your app, or specify scripts.start in your package.json.

// Procfile
web: node server.js

// package.json
"scripts": {
  "start": "node server.js"
},

https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.