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
//Read json object from json file. | |
//Write json object to json file | |
var fs = require('fs') | |
var util = require('util') | |
// __dirname is folder where script is running | |
// NOTE: Use always " in json file content | |
var cfgFile = __dirname + "/anything.json" |
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
// How wait inside of loop... | |
// Countdown | |
var counter = 10 | |
var countdown = function() { | |
console.log(counter) | |
counter-- | |
return (counter > 0) | |
} |
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 crypto = require('crypto') | |
// Encrypt/Decrypt a string | |
var key = "SecretKey" | |
, message = "This is the text to cipher!" | |
// Encrypting | |
var cipher = crypto.createCipher('des-ede3-cbc', key) | |
, cryptedMessage = cipher.update(message, 'utf8', 'hex') | |
cryptedMessage+= cipher.final('hex') |
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 varName1 = "varName2" | |
global[varName1] = "Hello World" // This is the important line ;) | |
var staticVarName = global[varName1] | |
console.log("Var1: Name/Value : varName1/" + varName1) | |
console.log("Var2: Name/Value : " + varName1 + "/" + global[varName1]) | |
console.log("Static Var: Name/Value : staticVarName/" + staticVarName) |
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 crypto = require('crypto') | |
, fs = require('fs') | |
var sourceFile = __dirname + "/testFile.txt" | |
, targetFile = __dirname + "/testEncryptedFile.txt" | |
, key = "SecretKey" | |
, algorithm = 'aes192' // Another algorithms: 'des-ede3-cbc' | |
, cipher = crypto.createCipher(algorithm, key) | |
, decipher = crypto.createDecipher(algorithm, key) | |
, rs = fs.ReadStream(sourceFile) |
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
// How to encrypt/decrypt with ursa module (asymmetric cryptology) | |
var ursa = require('ursa') | |
, message = 'Hello world!' | |
, encoding = 'base64' | |
// Creating a pair of keys (a private key contains both keys...) | |
console.log('Generating Keys Pair...') | |
var keys = ursa.generatePrivateKey() | |
// Making a private key |
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
// All you need to know about Mocha testing in 60 lines | |
// Mocha Testing: http://visionmedia.github.io/mocha/ | |
// Installation: npm install -g mocha | |
// Run: mocha [test folder or test file] | |
// Example: mocha . (Run all js tests in folder) | |
// | |
// Usefull parameters: | |
// mocha -w . : Watch file changes and re-run tests | |
// mocha -d . : Debug mode |
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
// How to send message from A user to B user, encrypting it (asymetric cryptology) and sign it | |
var ursa = require('ursa') | |
, message = 'Hello world!' | |
, encoding = 'base64' | |
, buffer = new Buffer(message, 'ascii') | |
// Creating a pair of keys of user A (a private key contains both keys...) | |
console.log('Generating Keys Pair of user A...') | |
var keysA = ursa.generatePrivateKey() |
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
// Managing websocket with socket.io | |
// Setting a web socket and sending a message from client to server. | |
// Server side | |
var app = require('express')() | |
, util = require('util') | |
, server = require('http').createServer(app) | |
, io = require('socket.io').listen(server) | |
, port = 8013 |
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
// How to create a simple web service with Express | |
// In App.js | |
// Dependencies | |
var express = require('express') | |
, http = require('http') | |
, port = 8080 | |
// Application | |
var app = express() |