Hi. I am following tutorials and learning a lot but no one has really
broken down app.js to a newbie.
So far with success I have my server running, I've installed Express and
socket.io and made a little chat page that works. I did this by adding the
following to app.js
var http = require('http').Server(app);
var io = require('socket.io')(http);
After the default 404 error handlers created by Express I add
io.on('connection', function(socket){
socket.on('disconnect', function(){
});
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
Finally I created a chat.js in public/javascripts/ so the user can chat.
Question #1: Should I be initializing the socket in app.js? What if I have
some static page that doesn't need any web socket stuff?
Question #2: I am trying the same thing with node-myqsl, In app.js:
var mysql = require('mysql');
But the only way I can get queries to work is to place them all in app.js.
That doesn't seem proper. Where do I put these additional modules? Where do
I store all my prepared queries?
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'admin'
});
connection.query('SELECT email FROM user.users', function(err, rows, fields) {
if (err) throw err;
});
connection.end();
Thanks for any help explaining!
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/fd21651a-5c1c-4b40-bd10-1c92b004217b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.