-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (39 loc) · 1.36 KB
/
server.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
var express = require('express'),
fs = require('fs'),
bodyParser = require('body-parser');
var app = express();
app.use(
"/", //the URL throught which you want to access to you static content
express.static(__dirname) // where your static content is located in your filesystem
);
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/words', function (req, res) {
var english = req.body.english;
var korean = req.body.korean;
var example = req.body.example.replace(english, '**' + english + '**');
fs.appendFile('/Users/qoo/Documents/English - Words.md', '| ' + english + ' | ' + korean + ' | ' + example + ' |\n', function (err) {
if (err) return console.log(err);
res.end('Success');
});
});
app.post('/expressions', function (req, res) {
var content = req.body.content;
var id = req.body.id;
if (id === 'expressions')
{
fs.appendFile('/Users/qoo/Documents/English - Nice Expressions.md', '\n>' + content + '\n\n***\n', function (err) {
if (err) return console.log(err);
res.end('Success');
});
}
else // id === 'ask-to-briana'
{
fs.appendFile('/Users/qoo/Documents/English - Ask To Briana.md', '\n>' + content + '\n\n***\n', function (err) {
if (err) return console.log(err);
res.end('Success');
});
}
});
app.listen(8000, function () {
console.log('Server runs on 8000');
});