-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_tutorial.js
46 lines (35 loc) · 1.03 KB
/
index_tutorial.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
const express = require('express')
const mongoose = require('mongoose')
const app = express()
const port = 3000
//Connect to DB
mongoose.connect('mongodb://localhost/test', {
useNewUrlParser: true,
useUnifiedTopology: true
});
const db = mongoose.connection;
//Schema constructor
const mySchema = new mongoose.Schema({
key: String,
property: String
});
//Create a model
const myModel = mongoose.model('my-collection', mySchema);
app.use(express.json())
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.post('/', function (req, res) {
const doc = new myModel(req.body)
doc.save()
// This command excecutes Revit by sending a command
exec('C: & cd "C:\\Windows\\System32" & start notepad.exe', (error, stdout, stderr) => {
if (error) console.log(`error: ${error.message}`);
if (stderr) console.log(`stderr: ${stderr}`);
console.log(`stdout: ${stdout}`);
});
res.send('Got a POST request and saved to DB')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})