Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CDL Michot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Michot
CDL Michot
Commits
79f0bb68
Commit
79f0bb68
authored
2 years ago
by
jmichot
Browse files
Options
Downloads
Patches
Plain Diff
added json possibility and modified readme for it
parent
d4a803ba
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+4
-2
4 additions, 2 deletions
README.md
config.json
+4
-0
4 additions, 0 deletions
config.json
tp1.js
+17
-7
17 additions, 7 deletions
tp1.js
with
25 additions
and
9 deletions
README.md
+
4
−
2
View file @
79f0bb68
...
...
@@ -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`
This diff is collapsed.
Click to expand it.
config.json
0 → 100644
+
4
−
0
View file @
79f0bb68
{
"name"
:
"config"
,
"prod"
:
false
}
This diff is collapsed.
Click to expand it.
tp1.js
+
17
−
7
View file @
79f0bb68
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
();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment