It may sound strange, But I'm trying to make very simple web chat, and I need help..
I made this far with node -
var http = require('http');
var fs = require('fs');
var path = require('path');
var messages = [];
// Simple Function to load HTML/JavaScript/CSS Files
function LoadHTML(html, requrl, res) {
var filePath = '.' + requrl;
if (filePath == './') {
filePath = './' + html;
}
var extname = path.extname(filePath);
var contentType = 'text/html';
switch (extname) {
case '.js':
contentType = 'text/javascript';
break;
case '.css':
contentType = 'text/css';
break;
}
fs.exists(filePath, function(exists) {
if (exists) {
fs.readFile(filePath, function(error, content) {
if (error) {
res.writeHead(500);
res.end();
}
else {
res.writeHead(200, { 'Content-Type': contentType });
res.end(content, 'utf-8');
}
});
}
else {
res.writeHead(404);
res.end();
}
});
}
http.createServer(function (req, res) {
LoadHTML('index.html', req.url, res);
}).listen(8125);
The HTML/CSS I'm using - http://jsfiddle.net/yZ5at/
From here I'm stuck.. I want that when the user type something into the textarea and hit enter he's text will be shown in the chat div.
But how can I do that? any help please?
well you're not doing anything with your requests, so maybe next step for you is checking out socket.io or making some client-side scripts for ajax calls to pass the text in textarea to the server and retrieve new messages. In any case that simple loadHTMl function is not enough