Skip to content
Snippets Groups Projects
Commit 79f0bb68 authored by jmichot's avatar jmichot
Browse files

added json possibility and modified readme for it

parent d4a803ba
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,8 @@ npm install
To run the app, you have 3 choices :
- Pass args directly in the command line `node tp1.js --configuration config.yml`
- Use env var : first export the var `export FICHIER_DE_CONFIGURATION="config.yml"` then run `node tp1.js`
- Pass args directly in the command line `node tp1.js --configuration $CONF_FILE`
- Use env var : first export the var `export FICHIER_DE_CONFIGURATION="$CONF_FILE"` then run `node tp1.js`
- Use file written in the source code by just running `node tp1.js`
`$CONF_FILE` can be `config.yml` or `config.json`
{
"name": "config",
"prod": false
}
const yaml = require('js-yaml');
const fs = require('fs');
import { load } from 'js-yaml';
import { readFileSync } from 'fs';
function readConfFile() {
const args = process.argv;
......@@ -13,12 +13,22 @@ function readConfFile() {
confFile = 'config.yml';
}
readFile(confFile);
}
function readFile(file) {
const fileExtension = file.split('.')[1];
if (fileExtension == 'yml') {
try {
const result = yaml.load(fs.readFileSync(confFile));
const result = load(readFileSync(confFile));
console.log(result);
} catch (e) {
console.error(e);
}
} else if (fileExtension == 'json') {
const jsonFile = require('./' + file);
console.log(jsonFile);
}
}
readConfFile();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment