Skip to content

Instantly share code, notes, and snippets.

@tbeseda
Created December 29, 2011 21:19
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tbeseda/1536247 to your computer and use it in GitHub Desktop.
Save tbeseda/1536247 to your computer and use it in GitHub Desktop.
Basic HTTP Auth with Express for Node.js
express = require 'express'
app = express.createServer()
auth = express.basicAuth 'yourmom', 'p4ssw0rd'
app.get '/', auth, (req, res) ->
res.send your_super_secret_stuff
app.listen 3000, ->
console.log "Listening on #{port}"
express = require 'express'
app = express.createServer()
auth = express.basicAuth 'yourmom', 'p4ssw0rd'
# Specify auth middleware and fire off next
app.get '/', auth, (req, res, next) -> next()
# Set up static middleware *after* your routes
app.use express.static "#{__dirname}/public"
app.listen 3000, ->
console.log "Listening on #{port}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment