-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (30 loc) · 1.07 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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var morgan = require('morgan');
var mongoose = require('mongoose');
var jwt = require('jsonwebtoken');
var config = require('./app/config');
var User = require("./app/models/user");
var Ag = require("./app/models/agro");
var AgRouter = require('./app/routes/agro');
var UserRouter = require('./app/routes/user');
app.set('appSecret', config.secret);
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
var port = process.env.PORT || 3000;
// Database connection
mongoose.connect( config.database , function(err, database){
console.log("Connected to database successfully.");
});
// Using morgan to log requests to the console
app.use(morgan('dev'));
app.use('/', UserRouter);
app.use('/api', AgRouter);
app.get('/', function(req, res){
res.send({"status": true, "message": "Welcome to Agronization Rest Api"});
});
app.listen(port, function(){
console.log("Listening to port 3000");
});
console.log("connected..");