-
Notifications
You must be signed in to change notification settings - Fork 4
Setup
You can access the hosted websites to experience yourself first.
-
Install JOR to your node project:
$ npm install json-on-relations --save
-
Create the database in MySQL:
After you installed MySQL, copy file "node_modules/json-on-relations/MDB.sql" to your sql console and execute. The script will create database 'MDB' which contains all the tables and the data.
Please also create a DB user with full permission on data definition and manipulation. The DB user will be used for JOR to connect with MySQL.
-
In your NodeJS project:
Copy the folder
node_modules/json-on-relations/dist
and its belongings to your project root.Create
server.js
in your project root with following codes:const express = require('express'); const app = express(); // We don't want to serve sessions for static resources const path = require('path'); app.use(express.static(path.join(__dirname, 'dist/jor'))); const cors = require('cors'); // Allow cross site requests app.use(cors()); app.use(require('body-parser').json()); const compress = require('compression'); app.use(compress()); // Routing const routes = require('json-on-relations').Routes; app.use('/', routes); // The index page as an entry point app.route('*').get( (req, res) => { res.sendFile(path.join(__dirname, '../dist/jor/index.html')); }); process.on('SIGINT',function(){ console.log("Closing....."); process.exit() }); const entityDB = require('json-on-relations').EntityDB; entityDB.setConnPool('mysql', { // Set the connection pool to your mysql DB. // Currently, we only support mysql. connectionLimit : 10, host: 'localhost', // To be replaced by your DB host user: 'nodejs', // To be replaced by your own DB user password: 'nodejs', // To be replaced by your own DB password database: 'MDB', createDatabaseTable: true, multipleStatements: true, dateStrings: true, port: 3306 // replaced by your DB port. }); app.listen(3000, () => console.log('Example app listening on port 3000!'));
You should also install the involved packages: express, path, cors, body-parse, and compression.
-
Start the server:
$ node server.js
-
You should now be able to open the following links: