Is there a way to stop the YAML parser from including question marks in its output?

Looking to create a basic docker compose setup and integrate it into an existing file. The yaml parser found here seems promising, but I'm struggling with the question mark that appears in its output.

This is the content of my current docker compose template:

version: "3.9"
name: "org"
services:
    memory:
        image: redis/redis-stack:7.2.0-v7
        # ...
networks:
    default:
        name: org
        external: true

I am attempting to introduce a new service into this template:

import { readFile, writeFile } from 'node:fs/promises'
import { parseDocument } from 'yaml'

const doc = parseDocument(await readFile('./docker-compose.yml', 'utf8'))

doc.addIn(['services'], {
    'my-service': {
        'image': '${CONTAINER_CONN_STR}:${APP_VERSION:-latest}',
        'ports': ['${GDEVOPS_APP_PORT}:${APP_PORT}']
    }
})

await writeFile('./sample.yml', String(doc))

The resulting sample.yaml file looks like this:

version: "3.9"
name: "org"
services:
    memory:
        image: redis/redis-stack:7.2.0-v7
        # ...
  ? my-service:
      image: ${CONTAINER_CONN_STR}:${APP_VERSION:-latest}
      ports:
        - ${GDEVOPS_APP_PORT}:${APP_PORT}
networks:
    default:
        name: org
        external: true

How can I remove the question mark prefix from my service?

Answer №1

To ensure keys are required to be scalars and always use implicit notation, pass the option {simpleKeys: true} when generating the string:

await writeFile('./sample.yml', String(doc, {simpleKeys: true}))

Referencing the official documentation:

simpleKeys    boolean     false   Require keys to be scalars
                                  and always use implicit rather
                                  than explicit notation.

The distinction between an "explicit mapping key" and an "implicit mapping key" is explained here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you suggest an efficient method for routing with EJS templates on an Express server without constantly repeating code?

Assuming my app consists of two views: index.ejs and profile/index.ejs, I aim to set up routing using express code as shown below. /* GET home page. */ router.get('/', function (req, res, next) { res.render('index'); }); /* GET pr ...

The dependency graph of npm modules shows significant differences

I've been exploring the capabilities of the npm-remote-ls package to analyze dependency trees for modules. This tool is installed globally on my system. When I execute Command 1: npm-remote-ls object-assign The tree structure displayed is as follows ...

Jquery for controlling the navigation menu

I'm new to JavaScript and facing 3 challenges: 1. When I click on the parent <li>, the correct content of the child <sub> does not show up. Each category like "colors, shapes, sizes" should have corresponding child categories like "green, ...

What is the correct way to align text in jsPDF?

I'm currently encountering an issue with the jsPDF library. Although PDF generation works fine, I am struggling to justify text properly. The align: 'justify' attribute seems to function the same as align: 'left', and setting a spe ...

I'm trying to set an object value for this select element, and while I have managed to do so, I am struggling to display the title of the selected object. Can anyone help me

I am struggling to display the title of the selected object in this select element. Can anyone help me understand why my code is not showing the title? Here is the code snippet: const [selectedCategory, setSelectedCategory] = useState(""); const categor ...

Decode a chunked binary response using the Fetch API

Is there a way to properly handle binary chunked responses when using the Fetch API? I have implemented the code below which successfully reads the chunked response from the server. However, I am encountering issues with the data being encoded/decoded in a ...

ui-grid row size set to automatically adjust using rowHeight : 'auto'

Has anyone else experienced this strange behavior with ui-grid? When I set the rowHeight to auto, each cell in the same row ends up with different heights. One of the cells contains multiline data, which seems to be causing issues for ui-grid. I've ev ...

The JavaScript .load() function fails to run

Attempting to create a straightforward Newsfeed page based on user interests. Here is the code I have implemented for this purpose. The issue I'm facing is that while the code works fine on my local server, it encounters problems when running on an on ...

Using gulp to compile a Vue component without the need for `require` statements

I'm currently exploring the process of constructing a component with Gulp. Right now, I am working on a Vue component that has the following structure: my-component.vue <template> <div class="foo"> </div> </template> < ...

"Vercel encounters a read-only file system when trying to change file

Hey folks, I've been using vercel for deploying my project. There's an issue with one of the dependencies in my NextJS project, which is located inside the node_modules folder. This dependency is supposed to read and write files within its own di ...

An overabundance of parallax visuals

I'm currently working on a static website that features several parallax images dividing each section. However, I've run into an issue as I continue to add more sections and parallax images. Some of the images at the bottom of the website are shi ...

Incorporate Vuetify's v-stepper seamlessly with Vue router for dynamic functionality

Seeking assistance in integrating vuetify's v-stepper with vue router. Specific requirements include: Assigning each step its own route (e.g. /myform/step1, /myform/step2, /myform/step3, etc) Creating components for each step that are dynamically lo ...

Transfer PHP variables into a JavaScript array for dynamic data population

Similar Question: Dynamic Pie Chart Data in Javascript and PHP This snippet of code is utilized for populating a pie chart using javascript: <script type="text/javascript"> var agg = { label: 'Aggressive', pct: [60, 10, 6, 30, 14 ...

Enhance data table by displaying a set number of rows that do not completely fill the table's height

I'm currently attempting to implement a v-data-table with fixed header and footer. However, I've encountered an issue where if I set the table height to be larger than the row height, the table takes on the defined height and the footer ends up b ...

Tips on resolving the problem of a user surpassing their 24-hour sending limit

Hey there! I need some assistance with a contact form I'm developing using react and node.js. I've set up both the front end and backend, and everything was running smoothly for up to 25 emails a day. However, I've started encountering an er ...

AngularJS - Click event failing to trigger controller function

I am currently honing my skills in Angularjs and Nodejs through working on a project. Following a helpful tutorial, I have structured my folders and configured my routes. Issue: I implemented a method called isActive to update ng-class when a tab is ...

Failure to retrieve data with ajax call in php script

I am a beginner in the world of JS and PHP. I am taking on the challenge of teaching myself. Following the guidance provided in this answer from Stack Overflow, I attempted to implement it in my project. Unfortunately, I am facing challenges and would gre ...

Is there a way for me to provide the product ID based on the selected product?

Is there a way to store the IDs of selected products in a dynamic form with multiple product options? I am able to see the saved products in the console.log(fields, "fields");, but how can I also save the selected product IDs? Any guidance on th ...

What is causing the error message of "prop id does not match the rendered server output" to appear on my screen?

https://i.stack.imgur.com/VOLDT.png I've been working on a nextjs redux project and I keep running into this error whenever I refresh my page. Despite searching for a solution, I haven't been able to resolve it. The official next js blog suggest ...

Is there a way to postpone these animations without relying on setTimeout?

As I develop a single-page website, my goal is to smoothly transition between sections by first animating out the current content and then animating in the new content. Currently, I have achieved this using setTimeout(), where I animate out the current con ...