Skip to content

Instantly share code, notes, and snippets.

@loonison123
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save loonison123/803540a203c14fddb876 to your computer and use it in GitHub Desktop.

Select an option

Save loonison123/803540a203c14fddb876 to your computer and use it in GitHub Desktop.
Node.js serve static files
var express = require('express');
var app = express();
// Put static files in a public folder in the same directory as app.js
app.use(express.static(__dirname + '/public'));
app.set('port', 3000);
app.listen(app.get('port'), function () {
});
// Now client side access the static content (Using: localhost:3000 as root URL)
<script src="localhost:3000/yourjsfile.js"></script>
// Incorrect
<script src="localhost:3000/public/yourjsfile.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment