forked from deleepa/simple-api-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (38 loc) · 1.13 KB
/
app.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
/*
* Author: Deleepa
* Description: The entry point to the server application.
*/
//use require to init all the packages
var express = require('express');
var config = require('dotenv').config();
var connection = require('./database');
var userApi = require('./routes/user-api')(connection);
var bodyParser = require('body-parser');
//create the express application
var app = express();
//parse multipart forms : application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
//parse all application/json
app.use(bodyParser.json());
/**
* @param {path} '/'
* @param {callback} function(req, res)
* @desc This function returns a string to tell the user to use the /api endpoints
*/
app.get('/', function(req, res) {
res.send('hello world!');
});
/**
* @param {path} '/api/users'
* @param {router} userApi
* @desc This is where the middleware for the user api is being set
*/
app.use('/api/users', userApi);
/**
* @param {port} 3000
* @param {callback} function()
* @desc This function starts the server
*/
app.listen(3000, function() {
console.log('server is listening at port 3000..');
});