|
1 | 1 | # GEDCOM-file-to-JSON-using-Node-JS-with-ES6
|
| 2 | + |
| 3 | +1. npm install |
| 4 | + |
| 5 | +2. node app.js |
| 6 | + |
| 7 | +3. Run your localhost:8080 |
| 8 | + |
| 9 | +Description: |
| 10 | + This simple code will return the gedcom file to json using ES6. |
| 11 | + |
| 12 | +Usage: |
| 13 | +------------------ |
| 14 | +app.js |
| 15 | +------------------ |
| 16 | +1. Set the Babel Register, To Convert your Ecmascript 6 code to ecmascript 5. |
| 17 | +--------------------------------------------------- |
| 18 | + require('babel-register')({ |
| 19 | + presets: [ 'es2015' ] |
| 20 | + }); |
| 21 | + |
| 22 | +2. Define the module(s), Where we use ES6. |
| 23 | +------------------------------------------ |
| 24 | + require('./index.js'); |
| 25 | + |
| 26 | +index.js |
| 27 | +------------------ |
| 28 | +1. import the header files. |
| 29 | +-------------------------------- |
| 30 | + import http from 'http'; /*--- The HTTP module can create an HTTP server, It listen to server port 8080 ---*/ |
| 31 | + import fs from 'fs'; /*--- Import File systems module -----*/ |
| 32 | + import path from 'path'; /*--- Import Path module ------*/ |
| 33 | + import gedcom from 'parse-gedcom'; /*--- Parse ged file use gedcom parse module ----*/ |
| 34 | + |
| 35 | +2. Define the method using Arrow function. |
| 36 | +-------------------------------------------- |
| 37 | + http.createServer((req, res) => { |
| 38 | + fs.readFile(path.resolve(__dirname)+'/ged/ft.ged','utf-8',(err, data) => { |
| 39 | + var jsonArrayObj = JSON.stringify(gedcom.parse(data), null, 2); |
| 40 | + res.write(jsonArrayObj); |
| 41 | + }); |
| 42 | + }).listen(8080); |
0 commit comments