Skip to content

Instantly share code, notes, and snippets.

@zerobase
Last active December 20, 2015 08:59
Show Gist options
  • Save zerobase/6104936 to your computer and use it in GitHub Desktop.
Save zerobase/6104936 to your computer and use it in GitHub Desktop.
A simple Node.js application which give you a secure way to copy & paste a short text between devices.
// A simple Node.js application which give you an easy insecure way to copy & paste a short text between devices.
//
// To use this app:
// 1. On your terminal, run: node copy-and-paste-httpd.js
// 2. Open http://ip-address-on-your-lan:port/ in your browser.
// 3. Paste any text and submit.
// 4. Open the same address from another device and you'll see the text.
// 5. Now you're done.
// 6. Don't forget to exit the process. It's insecure until you kill the process.
var express = require('express');
var ejs = require('ejs');
var port = 3000; // HTTP port setting
var value = ''; // global variable
var app = express();
app.use(express.bodyParser());
app.get('/', function(req, res){
var template = '<form action="/" method="post"><input type="text" name="value" value="<%= value %>"></form>';
var html = ejs.render(template, { value : value });
res.send(html);
});
app.post('/', function(req, res){
value = req.body.value;
res.redirect('/');
});
app.listen(port);
console.log('Server running at http://127.0.0.1:'+port+'/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment