This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
io.configure(function (){ | |
io.set('authorization', function (handshakeData, callback) { | |
if(handshakeData.xdomain) | |
return callback(null, false); // Whoa! Tem cachorro nesse mato! | |
callback(null, true) // Bem vindo, usuário! | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var app = express(); | |
app.engine('jade',require('jade').__express); | |
app.get('/', function(req, res, next){ | |
res.render('index.jade', { | |
title : 'Hello world!' | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// require dos pacotes necessários | |
var http = require('http'); | |
var httpProxy = require('http-proxy'); | |
// inicializando o proxy e o servidor web | |
var proxy = httpProxy.createProxyServer(); | |
var server = http.createServer(); | |
// Aqui temos a nossa lista de aplicações | |
var apps = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var socketio = require('socket.io'); | |
var http = require('http'); | |
var app = express(); | |
var server = http.createServer(app); | |
var io = socketio.listen(server); | |
app.get('/', function(req, res){ | |
res.send('Hello world'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
var data = []; | |
var stream = request.get('http://url_do_stream'); | |
stream.on('data', function(buff){ | |
// Recebemos um buffer de dados | |
// vamos adicionar aos buffers | |
data.push(buff); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var winston = require('winston'); | |
var app = express(); | |
// Criando uma única instância do winston | |
var logger = new (winston.Logger)({ | |
transports: [ | |
new (winston.transports.Console)(), | |
new (winston.transports.File)({ filename: 'somefile.log' }) | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
var url = 'http://www.sitedofornecedor.com.br/getserver?username=meuusuario&password=minhasenha'; | |
request.get(url, function(err, res, body){ | |
if(err) | |
return throw(err); | |
// Aqui está o corpo da sua requisição. | |
console.log(body); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express(); | |
var mysql = require('mysql'); | |
var connection = mysql.createConnection({ | |
host: 'localhost', | |
user: 'root', | |
password: '' | |
}); | |
// Conectando com o banco |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set nocompatible " be iMproved | |
filetype off " required! | |
set rtp+=~/.vim/bundle/vundle/ | |
call vundle#rc() | |
" let Vundle manage Vundle | |
" required! | |
Bundle 'gmarik/vundle' | |
Bundle 'jelera/vim-javascript-syntax' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 - try / catch doesn't work with async codes, so you don't need to use | |
// 2 - You need to add a callback to be trigered when everything had run | |
module.exports = { | |
createNewUser: function (user, callback){ | |
connection.query('INSERT INTO users (email, first_name, last_name, password) VALUES ("?", "?", "?", "?")', [user.email, user.first_name, user.last_name, user.password], function(err, result) { | |
// We will pass the error and the result to the function | |
callback(err, result); | |
}); | |
} |
NewerOlder