forked from mitushaa/Sentiment-Analysis-using-node.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (38 loc) · 1.01 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 fs = require('fs');
var data = fs.readFileSync('website/words.json');
var words = JSON.parse(data);
console.log(words);
//console.log('server is starting');
var express = require('express');
var app = express();
var server = app.listen(3000, listening);
function listening(){
} console.log("listening...");
app.use(express.static('website'));
app.get('/add/:word/:score?', addWord);
function addWord(request, response) {
var data = request.params;
var word = data.word;
var score = Number(data.score);
var reply;
if (!score) {
reply= {
msg: "You score is required."
}
}else {
words[word] = score;
var data= JSON.stringify(words, null,2);
fs.writeFile('words.json',data,finished);
function finished(err) {
console.log('all set.');
}
reply = {
msg: "Thank you for submitting your score."
}
}
response.send(reply);
}
app.get('/all', sendAll);
function sendAll(request, response) {
response.send(words);
}