-
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 install 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 'nodejs' with password 'nodejs'. By default, Portal uses credential 'nodejs/nodejs' to connect MySql at port 3306. You can of course change the default settings. Please refer the next step.
-
In your NodeJS project:
Copy the folder
node_modules/json-on-relations/dist
and its belongings to the project root.Create
server.js
in the 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: