Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created March 7, 2015 19:42
Show Gist options
  • Save WebReflection/5cdfe5adc4c3a284b669 to your computer and use it in GitHub Desktop.
Save WebReflection/5cdfe5adc4c3a284b669 to your computer and use it in GitHub Desktop.
A simple one file technique to bring JS on the client and the server
/** server */
var
port = 3000,
server = require('http').createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<!DOCTYPE html>'.concat(
'<html>',
'<head>',
'<script>(', client, ').call(this);</script>',
'</head>',
'</html>'
));
})
;
server.listen(port, function () {
console.log('listening on *:' + port);
});
/** client */
function client() { 'use strict';
alert('Hello World!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment