On Github keogh / itson-navojoa-slides
Chat con Angular.js + Node.js + Socket.io + Bower + Grunt.js + Bootstrap
By Isaac Zepeda
2014
Web Developer
Ruby
Javascript
Angular.js
Node.js
...
+ + + + +
angular.module('app', []) .controller('MainCtrl', function ($scope) { $scope.world = 'Mundo'; });
<html ng-app="app"> <body ng-controller="MainCtrl"> Hello {{world}}! </body> </html>
git clone git@github.com:keogh/itson-navojoa-seed.git chat-app
Desde la carpeta del proyecto
npm install bower install
npm install -g grunt grunt-cli
module.exports = function (grunt) { require('load-grunt-tasks')(grunt); grunt.initConfig({ connect: { server: { options: { port: 9000, hostname: 'localhost', livereload: 35729, base: 'app' } } } }); grunt.registerTask('server', [ 'connect:server' ]); }
grunt server
var io = require("socket.io").listen(8080); var users = []; io.sockets.on('connection', function (socket) { socket.on('username', function (username) { users.push(username); io.sockets.emit('users', users); socket.on('msg', function (msg) { io.sockets.emit('msg', username, msg); }); socket.on('disconnect', function () { users.splice(users.indexOf(username), 1); io.sockets.emit('users', users); }); }); });