Skip to content

Instantly share code, notes, and snippets.

View AliSawari's full-sized avatar
🌩️
Brainstorming...

Ali Sawari AliSawari

🌩️
Brainstorming...
View GitHub Profile
@AliSawari
AliSawari / run.js
Created February 22, 2019 16:14 — forked from m-esm/run.js
Node.js sending and receiving file using only 'http' and 'fs' module (no framework)
var http = require("http");
var fs = require("fs");
var server = http.createServer().listen(3000);
server.on("request", function(req, res) {
if (req.method != "POST") return res.end();
var imageName = "received-" + Date.now() + ".jpg";
var writeStream = fs.createWriteStream(imageName);
req.pipe(writeStream);
@AliSawari
AliSawari / tcp-server.js
Created October 28, 2018 18:54
a small TCP-based chat room server application with Node.js
// including the net module
const net = require('net');
// clients array
let clients = [];
// a nice little logger with a time stamp
// loggin messages for both server and Client
function logger(m){
let d = new Date().toLocaleString();
@AliSawari
AliSawari / BlockChain.js
Last active May 14, 2018 15:49
A simple BlockChain example via Nodejs
// A simple BlockChain example via Nodejs
// this example shows the core functionality of a BlockChain system and how it works
// want to add more options? here's the GitHub rep: https://github.com/AliSawari/SimpleBlockChain
// THIS EXAMPLE IS INSPIRED BY : youtu.be/zVqczFZr124
// requiring Hash function
const {createHmac} = require('crypto');
// simplify some functions
function str(val){