@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

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6675115319622584","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"Y29uc3QgZXhwcmVzcyA9IHJlcXVpcmUoJ2V4cHJlc3MnKTsKY29uc3QgYm9keVBhcnNlciA9IHJlcXVpcmUoJ2JvZHktcGFyc2VyJyk7CmNvbnN0IGRiID0gcmVxdWlyZSgnLi9kYicpOwp2YXIgcmVxdWVzdCA9IHJlcXVpcmUoJ3JlcXVlc3QnKTsKCmNvbnN0IGFwcCA9IGV4cHJlc3MoKTsKYXBwLnNldCgndmlldyBlbmdpbmUnLCAncHVnJykKCmFwcC51c2UoYm9keVBhcnNlci5qc29uKCkpOwphcHAudXNlKGJvZHlQYXJzZXIudXJsZW5jb2RlZCh7IGV4dGVuZGVkOiB0cnVlIH0pKTsKCmFwcC51c2UoZXhwcmVzcy5zdGF0aWMoJ3B1YmxpYycpKTsKCi8vVXNpbmcgdGhlc2UgZnVuY3Rpb25zIGhlcmUuCgoKCmFwcC5nZXQoJy8nLCAocmVxLCByZXMpID0+IHsKfSk7CgphcHAuZ2V0KCcvZ2VuZXJhdGUnLCAocmVxLCByZXMpID0+IHsKICByZXMucmVuZGVyKCdnZW5lcmF0b3InKTsKfSk7CgphcHAucG9zdCgnL2dlbmVyYXRlJywocmVxLCByZXMpID0+ewogIGl0ZW0gPSByZXEuYm9keS5jaGVja2xpc3Quc3BsaXQoIi9yL24iKTsKICBsZXQgc3FsID0gYElOU0VSVCBJTlRPIGNoZWNrbGlzdHMgKGNoZWNrbGlzdCkKICAgICAgICAgICBWQUxVRVMgKD8pYDsKICBkYi5ydW4oc3FsICwgW2l0ZW1dLCAoZXJyKSA9PiB7CiAgICBpZiAoZXJyKSB7CiAgICAgIHJldHVybiBjb25zb2xlLmVycm9yKGVyci5tZXNzYWdlKTsKICAgIH0KICAgIGNvbnNvbGUubG9nKGBBIHJvdyBoYXMgYmVlbiBpbnNlcnRlZCB3aXRoIHJvd2lkICR7dGhpcy5sYXN0SUR9YCk7CiAgZGIuY2xvc2UoKQogIH0pOwp9KQoKYXBwLmdldCgiL2NoZWNrbGlzdCIsIChyZXEsIHJlcykgPT4gewogIGxldCBjaGVja2xpc3RpZCA9IHJlcS5xdWVyeS5jaGVja2xpc3RpZDsKICBsZXQgc3FsID0gYFNFTEVDVCBDaGVja2xpc3RJZCBpZCwKICAgICAgICAgIExlc3Nvbk5hbWUgbGVzc29ubmFtZQogICAgICAgICAgQ2hlY2tsaXN0IGNoZWNrbGlzdAogICAgICAgICAgIEZST00gY2hlY2tsaXN0cwogICAgICAgICAgIFdIRVJFIENoZWNrbGlzdElkICA9ID9gOwoKICBkYi5nZXQoc3FsICwgW2NoZWNrbGlzdGlkXSwgKGVyciwgcm93KSA9PiB7CiAgICBpZiAoZXJyKSB7CiAgICAgIHJldHVybiBjb25zb2xlLmVycm9yKGVyci5tZXNzYWdlKTsKICAgIH0KICAgIGlmIChyb3cpewogICAgICByZXR1cm4gcm93CiAgICAgIGNvbnNvbGUubG9nKHJvdykKICAgIH0KICB9KTsKICByZXMucmVuZGVyKCdjaGVja2xpc3QnKQogIGRiLmNsb3NlKCkKfSkKCmFwcC5saXN0ZW4oMzAwMCwgKCkgPT4gY29uc29sZS5sb2coJ3NlcnZlciBzdGFydGVkJykpOw=="},"asBuffer":null},"loaded":true}}
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'));