-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
35 lines (32 loc) · 916 Bytes
/
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
const net = require('net');
const dummyjson = require('dummy-json');
const JsonSocket = require('json-socket');
const template = `{
"receiver": {
"firstName": "{{firstName}}",
"lastName": "{{lastName}}",
"email": "{{email}}"
},
"price": {{float 10 200 '0.00'}},
"address": {
"country": "{{country}}",
"city": "{{city}}",
"street": "{{street}}",
"coordinates": {
"x": {{float -50 50 '0.00'}},
"y": {{float -25 25 '0.00'}}
}
},
"creationDate": "{{date '2015' '2021' }}",
}`;
const port = 8282;
const server = net.createServer();
server.listen(port);
server.on('connection', function(socket) {
socket = new JsonSocket(socket);
streamInterval = setInterval(function() {
const data = dummyjson.parse(template);
console.log(data);
socket.sendMessage(data);
}, 1000);
});