This file contains 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
const express = require('express'); | |
const app = express(); | |
//acts as a middleware | |
//to handle CORS Errors | |
app.use((req, res, next) => { //doesn't send response just adjusts it | |
res.header("Access-Control-Allow-Origin", "*") //* to give access to any origin | |
res.header( | |
"Access-Control-Allow-Headers", | |
"Origin, X-Requested-With, Content-Type, Accept, Authorization" //to give access to all the headers provided |
This file contains 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
//SERVER SCRIPT | |
var express = require('express'); | |
var app = express(); | |
var request = require('request'); | |
app.get('/:forwardParams',function(req,res){ | |
request.get('http://www.google.com/' + req.params.forwardParams, function (err, response) { | |
if(!err){ | |
res.send(response.body); | |
} | |
else{ |
This file contains 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 serverIndex = args.indexOf('--server') + 1; | |
if (!serverIndex) { | |
console.log('No port specified. use --port <portnumber> as arguments when starting this script'.red.bold); | |
process.exit(); | |
} | |
var server = args[serverIndex]; | |
var io = require('socket.io-client'); | |
var socket = io.connect(server); | |
socket.on('connect',function(){ |
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<title>Starter Template</title> | |
<meta name="description" content=""> |
This file contains 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 http = require('http'); | |
var fs = require('fs'); | |
var file = fs.createWriteStream("file.jpg"); | |
var request = http.get("http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg", function(response) { | |
response.pipe(file); | |
}); |
This file contains 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
const readline = require('readline'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
rl.on('line', (input) => { | |
console.log(`Received: ${input}`); | |
}); |
This file contains 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
//-------------------------------------------------------------------------------- | |
// SERIAL PORT HANDLER | |
// This module can be imported into nodejs using require method. | |
// It uses .start(device,baudrate); to create aconnection to the serial hardware | |
// After that, it manager disconnects to the hardware and retries. | |
// It employs an array buffer to slow down the processing of incoming commands | |
// to a speed that your program can handle | |
//-------------------------------------------------------------------------------- | |
var EventEmitter = require('events').EventEmitter; | |
var util = require('util'); |
This file contains 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 io = require('socket.io-client'); | |
var connectData = { server:"http://127.0.0.1:80"} | |
var socket = io.connect(connectData.server); | |
socket.on('connect',function(){ | |
console.log('Connected to main Server'); | |
}); | |
socket.on('disconnect',function(){ | |
console.log('Connected to main Server'); |
This file contains 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 http = require('http'); | |
var server = http.createServer(app); | |
var io = require('socket.io')(server); | |
app.use("/", express.static(__dirname + "/public")); | |
app.get("/", function (req, res) { | |
res.sendFile(__dirname + '/index.html'); | |
}); |