Serve static content from the current directory with node.js

This micro-tutorial assumes that you have already installed node.js.

Often when writing front-line JavaScript, you’ll find yourself wanting to serve content in the current directory without resorting to writing the node server for each folder. Thankfully http-server solves this problem with a nifty, node-based command-line tool to do just that.

npm install -g http-server

Once installed, jump into the terminal and place yourself in the directory that holds the static content. From there, it’s just a matter of keystrokes:

http-server [path] -p [port]

Path and port are optional. Should it find a sub-directory named ‘public’, it will be chosen as the HTTP root, if not – the current directory will assume its place. Port defaults to 8080.

More info: https://github.com/nodeapps/http-server

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s