Created
          April 27, 2012 08:57 
        
      - 
      
- 
        Save faridnsh/2507596 to your computer and use it in GitHub Desktop. 
    Express example
  
        
  
    
      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
    
  
  
    
  | /** | |
| * Module dependencies. | |
| */ | |
| var express = require('express'); | |
| var app = module.exports = express.createServer(); | |
| // Configuration | |
| app.use(express.bodyParser()); | |
| app.use(express.cookieParser()); | |
| app.use(express.session({secret : '133131'})); | |
| app.use(app.router); | |
| // Routes | |
| app.get('/', function(req, res){ | |
| if (req.session.auth) { | |
| console.log('up') | |
| res.send('welcome mane') | |
| } else { | |
| console.log('down') | |
| res.sendfile('./index.html') | |
| } | |
| }) | |
| app.get('/logout', function(req, res){ | |
| req.session.auth = false; | |
| res.redirect('/'); | |
| }); | |
| app.post('/login', function(req, res){ | |
| if (req.body.id === 'JS' && req.body.pass === 'JS') { | |
| req.session.auth = true; | |
| res.redirect('/') | |
| } else { | |
| res.send('go fuck ur slef') | |
| } | |
| }); | |
| app.listen(3000); | |
| console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); | 
  
    
      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
    
  
  
    
  | <!DOCTYPE HTML> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Done with Express and nodejs</title> | |
| </head> | |
| <body> | |
| <form action="/login" method="POST"> | |
| <input type="text" name="id" placeholder="Username" /> | |
| <input type="password" name="pass" placeholder="Password" /> | |
| <input type="submit" /> | |
| </form> | |
| </body> | |
| </html> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment