Created
March 7, 2015 19:42
-
-
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
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
/** 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