Skip to content

Instantly share code, notes, and snippets.

@jcarroyo
jcarroyo / index.js
Created February 8, 2016 00:35
Memory REST API
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var uuid = require('uuid');
var students = [];
// parse application/json
app.use(bodyParser.json());
@jcarroyo
jcarroyo / request.js
Last active February 1, 2016 07:22
Pure http Node.js to call a remote REST API.
var http = require('http');
var url = require('url');
var urlAPI = "http://jsonplaceholder.typicode.com/comments";
var urlParts = url.parse(urlAPI);
var options = {
protocol: urlParts.protocol,
hostname: urlParts.host,
port: urlParts.port || 80,
@jcarroyo
jcarroyo / chatClient.js
Last active May 26, 2016 04:16
Chat server and client
var readline = require('readline');
var net = require('net');
var port = process.env.CHATPORT || 8090;
var client = new net.Socket();
client.connect(port, '127.0.0.1', function() {
console.log('Connected');
});
client.setEncoding("utf8");
@jcarroyo
jcarroyo / echoClient.js
Created January 24, 2016 18:19
Simple demo for echo client
var net = require('net');
var client = new net.Socket();
client.connect(9090, "127.0.0.1", function(){
console.log("connected");
});
var times = 5;
var interval = setInterval(function(){
if(!times){
@jcarroyo
jcarroyo / echoServer.js
Created January 24, 2016 17:54
Very simple echo server in Node.js
var net = require('net');
var server = net.createServer(function(socket){
socket.on('data', function(data){
console.log('data received', data.toString());
socket.write(data, function(){
console.log("data re-sended");
})
});
}).listen(9090);
@jcarroyo
jcarroyo / portScanner.js
Last active January 26, 2016 02:22
A simple port scanner
var net = require('net');
var parameters = process.argv.slice(2, process.argv.length);
var timeOut = 2000;
console.log(parameters)
if(parameters.length == 1 && parameters[0] == "help"){
printHelp();
}
if(parameters.length != 2){