पर Node.js/Express/Socket.io एप्लिकेशन को तैनात करने का प्रयास करते समय एप्लिकेशन त्रुटि मैं इन सभी तकनीकों (कुछ हद तक जावास्क्रिप्ट सहित) के लिए बिल्कुल नया हूं, इसलिए आपको यहां मेरे साथ सहन करना पड़ सकता है।हेरोोक
मैंने सॉकेट.आईओ दस्तावेज़ों पर चैटएप ट्यूटोरियल का काफी बारीकी से पालन किया और एप्लिकेशन को कुछ हद तक मेरी पसंद में संशोधित किया; हालांकि, मुझे नहीं लगता कि मैंने सर्वर पर बातचीत और सामान के पक्ष में बहुत कुछ बदल दिया है। मेरी समस्या कोई फर्क नहीं पड़ता कि मैं क्या करता हूं, मैं अपने आवेदन को हेरोकू पर सफलतापूर्वक चलाने के लिए सक्षम नहीं कर सकता। ऐप लोड करने का प्रयास करते समय मुझे यह त्रुटि संदेश मिलता है:
एप्लिकेशन त्रुटि एप्लिकेशन में एक त्रुटि हुई और आपका पृष्ठ परोसा नहीं जा सका। कृपया कुछ ही क्षणों में पुनः प्रयास करें। यदि आप एप्लिकेशन स्वामी हैं, तो विवरण के लिए अपने लॉग देखें।
मुझे यकीन नहीं है कि मुझे कुछ स्पष्ट या क्या याद आ रहा है।
यहाँ मेरी मुख्य index.js फ़ाइल है:
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendfile('index.html');
});
app.use("/css", express.static(__dirname + '/css'));
//array of users currently in chat
var people = {};
io.on('connection', function(socket){
console.log('user connected!');
socket.on('join', function(name){
people[socket.id] = name; //create entry in 'people' with new user
socket.emit("update", "You have connected to the server.");
io.sockets.emit("update", name + " has joined the server.");
io.sockets.emit("update_people_list", people);
});
socket.on('disconnect', function(){
console.log('user disconnected!');
if(people[socket.id] != ""){
io.sockets.emit("update", people[socket.id] + " has left the server.");
delete people[socket.id];
io.sockets.emit("update_people_list", people);
}
});
socket.on('chat message', function(msg){
console.log('message: ' + msg);
io.sockets.emit('chat message', people[socket.id], msg);
});
});
// http.listen(3000, function(){
// console.log('listening on *:3000');
// });
index.html
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery.js"></script>
<script>
$(document).ready(function(){
var ready = false;
var socket = io.connect();
$("#chat").hide();
$(".canvasDiv").hide();
$("#name").focus();
//prevent form from being submitted without name
$("form").submit(function(event){
event.preventDefault();
});
//allows entering by hitting 'Enter' for name
$("#name").keypress(function(e){
if(e.which == 13) { //if ENTER key
var name = $("#name").val();
if(name != ""){
socket.emit("join", name);
$("#login").detach();
$("#chat").show();
$("#msg").focus();
ready = true;
}
}
});
$('#chatform').submit(function(){ //when submit chat message
socket.emit('chat message', $('#msg').val()); //emit message + value of input
$('#msg').val(''); //empty field?
return false; //so that the page doesn't refresh
});
//SOCKET LISTENING
socket.on('chat message', function(user, msg){
if(ready){
$('#messages').append("<p><strong><span class='chat-user'>" + htmlEntities(user) + " </span></strong>: " + htmlEntities(msg) + "</p>");
//adjust height and scroll as need be:
var $container = $('#messages');
var height = $container.get(0).scrollHeight;
$container.scrollTop(height);
}
});
socket.on("update", function(io_message){
if(ready){
$('#messages').append("<p class='notification'>" + htmlEntities(io_message) + "</p>")
}
});
socket.on("update_people_list", function(people){
if(ready){
$("#people").empty(); //clear to refresh it
$.each(people, function(client_id, name){
$('#people').append("<p class='notification'>" + htmlEntities(name) + "</p>");
});
var $container = $("#messages");
var height = $container.get(0).scrollHeight;
$container.scrollTop(height);
}
});
});
</script>
इसके अतिरिक्त, मेरी package.json फ़ाइल
{
"name": "socket-chat-example",
"version": "0.0.1",
"description": "my first socket.io app",
"dependencies": {
"express": "^4.6.1",
"socket.io": "^1.0.6"
}
}
Procfile:
web: node index.js
,210
.gitignore:
node_modules/
यह मेरी समस्या हल है। धन्यवाद। –
'हेरोकू लॉग' ने मुझे यह पता लगाने में मदद की कि अभिव्यक्ति devdependencies में स्थापित है और निर्भरताओं में नहीं। मैंने इसे निर्भरताओं में स्थापित किया और यह काम किया! धन्यवाद! – Siddharth