Last active
August 29, 2015 14:08
-
-
Save loonison123/803540a203c14fddb876 to your computer and use it in GitHub Desktop.
Node.js serve static files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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