-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (34 loc) · 1.03 KB
/
server.js
File metadata and controls
42 lines (34 loc) · 1.03 KB
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
const express = require('express');
const http = require('http');
const mongoose = require('mongoose');
require('./models/tick');
require('./models/user');
const routes = require('./api/routes');
const tickersaver = require('./tickersaver');
const bodyParser = require('body-parser');
const socket = require('socket.io');
const cycle = require('./cycletrading/socket');
const dotenv = require('dotenv');
dotenv.config();
// connecting to mongo
mongoose.promise = global.Promise;
mongoose.connect(process.env.MONGODB_URI);
// starting api
let app = express();
let server = http.createServer(app);
let port = process.env.PORT || 3000;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
});
server.listen(port);
routes(app);
// starting socket.io for cycle trading
let io = socket();
io.listen(server);
cycle(io);
// starting to save ticks
tickersaver.start();
console.log('RESTful API server and socket.io started on: ' + port);