SHARE
TWEET

Untitled

a guest Dec 6th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express')
  2. const app = express()
  3.  
  4. const fs = require('fs')
  5.  
  6. const port = 3000
  7. const messages = []
  8. let errorMessage;
  9.  
  10. app.use(express.urlencoded({ extended: true}))
  11. app.set('view engine', 'ejs')
  12.  
  13. app.get('/', (request, response) => {
  14.     response.render('index', { messages, errorMessage })
  15. })
  16.  
  17. app.post('/entry/create', (request, response) => {
  18.     const body = request.body
  19.    
  20.     const name = body.name
  21.     if (!name) errorMessage = 'The name must be provided.'
  22.     const message = body.message
  23.     if (!message) errorMessage = 'The message must be provided.'
  24.     messages.push({ name, message })
  25.    
  26.     response.redirect('/')
  27. })
  28.  
  29. app.listen(port, () => console.log(`The Guestbook server is listening on port ${port}.`))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top