Skip to content

Instantly share code, notes, and snippets.

@kioku-systemk
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kioku-systemk/1076c5d8218aaa07a8c6 to your computer and use it in GitHub Desktop.
Save kioku-systemk/1076c5d8218aaa07a8c6 to your computer and use it in GitHub Desktop.
Node.jsでHTMLを書き始めるテンプレ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title></title>
</head>
<body>
</body>
</html>
/*jslint devel: true, browser: true*/
/*global require, process*/
//
// Simple node.js web server
//
var http = require('http'),
fs = require('fs'),
port = 8080;
var server = http.createServer(function (req, res) {
'use strict';
console.log('REQ>', req.url);
var file, fname;
if (req.url === '/') {
file = fs.readFileSync('index.html');
res.end(file);
} else {
try {
fname = req.url.substr(1, req.url.length); // remove '/'
file = fs.readFileSync(fname);
res.end(file);
} catch (e) {
res.writeHead(404, {'Content-Type': 'text/plain'});
res.end('not found\n');
}
}
});
if (process.argv.length > 2) {
port = process.argv[2];
}
server.listen(port);
console.log('start server "http://localhost:' + port + '/"');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment