Reputation: 754
I have 3 files :
server.js
containing node.js server (Using WebSocket-Node)client.js
containing websocket codefrontend.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:
- .git
- node_modules // containing websocket
- client.js
- frontend.html
- server.js
- 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 !
Upvotes: 0
Views: 950
Reputation: 916
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
Upvotes: 1