repl.it
@JohnsonTheGreat/

Express Checklist Generator 1

Express

Program that allows users to input a checklist and have it convert into an online interactive checklist.

fork
loading
Files
  • index.js
  • views
  • db.js
  • db1.sqlite3
  • package-lock.json
  • package.json
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const express = require('express');
const bodyParser = require('body-parser');
const db = require('./db');
var request = require('request');

const app = express();
app.set('view engine', 'pug')

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.use(express.static('public'));

//Using these functions here.



app.get('/', (req, res) => {
});

app.get('/generate', (req, res) => {
  res.render('generator');
});

app.post('/generate',(req, res) =>{
  item = req.body.checklist.split("/r/n");
  let sql = `INSERT INTO checklists (checklist)
           VALUES (?)`;
  db.run(sql , [item], (err) => {
    if (err) {
      return console.error(err.message);
    }
    console.log(`A row has been inserted with rowid ${this.lastID}`);
  db.close()
  });
})

app.get("/checklist", (req, res) => {
  let checklistid = req.query.checklistid;
  let sql = `SELECT ChecklistId id,
          LessonName lessonname
          Checklist checklist
           FROM checklists
           WHERE ChecklistId  = ?`;

  db.get(sql , [checklistid], (err, row) => {
    if (err) {
      return console.error(err.message);
    }
    if (row){
      return row
      console.log(row)
    }
  });
  res.render('checklist')
  db.close()
})

app.listen(3000, () => console.log('server started'));