-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.js
46 lines (38 loc) · 1.24 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
////////// Node.JS INITIALIZATION //////////////
var express = require('express')
, bodyParser = require('body-parser')
, Sequelize = require('sequelize')
, http = require('http')
, restful = require('sequelize-restful')
, sequelize = new Sequelize('test', 'root', 'password', {
logging: console.log,
define: {
timestamps: false
}
})
, app = express();
var port = process.env.PORT || 3000;
app.use(bodyParser());
////////////////////////////////////////////////
/////////// MODELS DEFINITIONS /////////////////
// User model definition
var User = sequelize.define('users', {
name: Sequelize.STRING,
password: Sequelize.STRING
}
);
// Project model definition
var Project = sequelize.define('projects', {
name: Sequelize.STRING
}
);
// Relationship definition
User.hasMany(Project, {foreignKey: 'user_id' });
///////////////////////////////////////////////
/////////// MAGICAL PIECE OF CODE /////////////
app.use(restful(sequelize));
///////////////////////////////////////////////
/////////// LAUNCH THE SERVER /////////////////
app.listen(port);
console.log('Magic happens on port ' + port);
////////////////////////////////////////////////