Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active January 4, 2016 12:08
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 joyrexus/8619409 to your computer and use it in GitHub Desktop.
Save joyrexus/8619409 to your computer and use it in GitHub Desktop.
Simple http server

A simple http server to serve files relative to your current working directory.

Install the serve command with npm -g install.

Use serve [PORT] to start serving files in the current directory via the specified port number (default is 3000).

Open http://localhost:3000/ to view your web pages.

See Also

connect = require 'connect'
port = process.argv[2] or 3000
connect()
.use(connect.static(__dirname))
.use(connect.logger('dev'))
.listen port
console.log 'Listening on port ' + port
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font-family: 'Helvetica Neue';
font-weight: 100;
font-size: 200px;
margin: 20px;
color: #777;
}
</style>
<div>It worked!</div>
(function() {
var connect, port;
connect = require('connect');
port = process.argv[2] || 3000;
connect()
.use(connect["static"](__dirname))
.use(connect.logger('dev'))
.listen(port);
console.log('Listening on port ' + port);
}).call(this);
{
"name": "http-server",
"version": "0.0.1",
"description": "A simple http server.",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"bin": {
"serve": "./index.js"
},
"dependencies": {
"connect": "~2.12.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment