Skip to content

Instantly share code, notes, and snippets.

@jonkemp
Last active October 17, 2022 01:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonkemp/4ebc0a77091de32cd980 to your computer and use it in GitHub Desktop.
Save jonkemp/4ebc0a77091de32cd980 to your computer and use it in GitHub Desktop.
Starting a development server

Start a dev server to preview your work using Python, Ruby or Node.js

Requirements

Mac OS: Ruby and Python are pre-installed. Install Node.js.

Windows: First install Ruby, Python or Node.js

Ruby

Install the asdf gem.

gem install asdf

Change to the directory you want to host and type asdf from the terminal or command prompt.

Navigate to http://localhost:9292/ in your browser to preview your site.

Python

Change to the directory you want to host and type python -m SimpleHTTPServer 8080 (for port 8080 and Python 2) and python -m http.server 8080 (for port 8080 and Python 3) from the terminal or command prompt.

Navigate to http://localhost:8080/ in your browser to preview your site.

Node.js

From the terminal or command prompt, type npm init and answer the questions from the prompts to create a package.json file.

Type npm install --save express to install express as a dependency and update your package.json file.

Create a JavaScript file called server.js and save it with the following contents.

var express = require('express'),
    app = express();

app.use( express.static( __dirname + '/public' ) );

var server = app.listen(3000, function() {
    console.log('Listening on port %d', server.address().port);
});

Put the files you wish to preview in a directory called public, and type node server.js from your parent directory.

Navigate to http://localhost:3000/ in your browser to preview your site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment