Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
CodeMirror: load default yaml file

I'm currently trying to get CodeMirror to load a yaml file for me.

Backend (slimmed down for stackoverflow):

    import fs from "fs-extra";
    import yaml from "js-yaml";

    const conf = yaml.load(fs.readFileSync('./config.yml', 'utf-8'));
        
    router.get('/', (req, res) => {
        res.render('settings.ejs', {
            page_name: 'settings',
            yaml_config: JSON.stringify(conf)
        });
    
        console.log(JSON.stringify(conf));
    });

Frontend:

    <div id="editor"></div>
    <script>
        const editor = CodeMirror(document.getElementById('editor'), {
            mode: 'yaml',
            styleActiveLine: true,
            lineNumbers: true,
            foldGutter: true,
            gutters: [
                "CodeMirror-linenumbers", "CodeMirror-foldgutter"
            ],
            theme: 'material',
            value: "<%= yaml_config%>"
        });
    </script>

Without the JSON.stringify will just load "[Object] [object], the console output of console.log(JSON.stringify(conf)); is: {"port":"3000","maxCPU":"30","maxMem":"4","maxDisk":"2"}, but whats being written to CodeMirror is {&#34;port&#34;:&#34;3000&#34;,&#34;maxCPU&#34;:&#34;30&#34;,&#34;maxMem&#34;:&#34;4&#34;,&#34;maxDisk&#34;:&#34;2&#34;}

config.yml;

---
port: '3000'
maxCPU: '30' # in %
maxMem: '4' # in GB
maxDisk: '2' # in GB

Any solutions to my problem?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!