Optimal method for writing to JSON file in NodeJS 10 and Angular 7?

Not sure if this question fits here, but it's really bothering me. Currently using Node v10.16.0. Apologies!

With Angular 7, fs no longer functions - what is the optimal method to write to a JSON file?

Importing a JSON file is now simple, but how can I write to it?

In regards to what I attempted:

component.ts:

import * as fs from 'fs';
[...]
saveChanges(changes) {
    fs.writeFile('config.json', JSON.stringify(config), null);

Error: `Module not found: Error: Can't resolve 'fs' `

Answer №1

Interacting with fs from within Angular is generally not recommended, as it is typically not the intended use case.

Angular serves as a Front-End Framework designed to connect data to a user interface within a browser setting, rather than in NodeJS environments.

If you find yourself trying to access file system operations in an Angular application, it's likely that you are utilizing a NodeJS server (such as express or Angular CLI) to host your application.

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

Exploring the contents of JSON data using json-server

In my database file db.json, I have the following data: { "cases":{ "TotalCount":1, "StartingPageNumber":1, "Data":[ { "Id":1, "CaseNumber":& ...

Using NestJS to import and inject a TypeORM repository for database operations

This is really puzzling me! I'm working on a nestjs project that uses typeorm, and the structure looks like this: + src + dal + entities login.entity.ts password.entity.ts + repositories ...

Parse the string into Json format

Trying to parse a string into JSON using the code snippet below: using Newtonsoft.Json; using Newtonsoft.Json.Converters; string final =" quoteDataObj : [{"symbol":"@CL.1","symbolType":"symbol","code":0,"name":"WTI Crude Oil (Sep\u002715)","shortN ...

Troubleshooting a GET Request Hanging Issue with Next.js 13 Route Handler

I'm currently encountering an issue with the new routing feature in my Next.js 13 project. I have a route handler set up in app/api/ingresos/route.ts with the code snippet below: import { NextResponse } from 'next/server'; import PocketBase ...

Extract targeted data fields from a JSON document

Whenever I attempt to display the json file, this is the output I receive: {'results': [{'alternatives': [{'confidence': 0.996, 'transcript': 'hi '}], 'final': True}, {'alternatives': [ ...

I am experiencing slow load times for my Angular 2 app when first-time users access it, and I am seeking assistance in optimizing its speed

Below, you'll find a snippet from my app.ts file. I'm currently working with angular2, firebase, and typescript. I'm curious if the sluggish performance is due to the abundance of routes and injected files? The application functions smoot ...

Having trouble constructing the JSon for ZigBee devices

Due to the lack of APIs, support, and other resources from commax, I am attempting to manually add unsupported devices to build my IoT home. However, I am currently facing difficulties in managing Zigbee dimmers with these devices. What seems to be the iss ...

Strategies for evaluating a Promise-returning imported function in Jest

I am currently facing an issue with a simple function that I need to write a test for in order to meet the coverage threshold. import { lambdaPromise } from '@helpers'; export const main = async event => lambdaPromise(event, findUsers); The ...

Developing a Python loop to mimic a "goto" style solution

My approach involves simulating a goto sequence. Is there a more elegant solution available? Note: The concept of storing the variables in a class variable was just for amusement (due to the .format() accessing story). n=0 while n==0: print("What is ...

What steps can I take to ensure that the upper and left sections of a modal dialog remain accessible even when the size is reduced to the point of overflow?

One issue I'm facing is with a fixed-size modal dialog where part of the content gets cut off and becomes inaccessible when the window shrinks to cause an overflow. More specifically, when the window is narrowed horizontally, the left side is cut off ...

Utilizing Date Model Binding in ASP.NET Core Framework

While working on an ASP.NET Core Web API, I encountered an issue with binding DateTime values. Specifically, I have two properties - minimumDate and maximumDate - for filtering a certain resource. These properties are part of a Filtering object that is po ...

Why is it that in Angular, console.log(11) is displayed before console.log(1)?

Can someone help me understand why my simple submit method is printing Console.log(11) before Console.log(1)? I'm confused about the order of execution. submit(value) { this.secServise.getUserById(this.currentUser.mgId).subscribe( uAddrs => { ...

Attaching dynamic data to a specific element within an array

I have successfully created a demo where elements can be dropped into a specific area and their top and left values are displayed. I have also added functionality to remove dropped items and move them between different blocks. However, I am encountering so ...

When using Vue with Vuetify, be aware that object literals can only specify known properties. In this case, the type 'vuetify' does not exist in the ComponentOptions of Vue with DefaultData

Started a fresh Vue project with TypeScript by following this guide: https://v2.vuejs.org/v2/guide/typescript.html If you don't have it installed yet, install Vue CLI using: npm install --global @vue/cli Create a new project and choose the "Manual ...

Determine data type using the generic type of a related property in Typescript

I am seeking a method to specify the type of a property based on the generic type of another property within the same context. For instance, consider the following: type Person = { id: number; name: string; } type Select<Value=unknown> = (props ...

Struggling to make the paste event function in Typescript

Here is a snippet of my Typescript code: const pasteFn = (e: ClipboardEvent) => { const { clipboardData } = e; const text = clipboardData?.getData('text/plain'); console.log(text); }; window.addEventListener('paste', pas ...

Tips for displaying an associative object array as td elements within a tbody in Nuxt

I'm having trouble displaying the property of an associative object array in my code. I attempted to utilize a v-for loop and wanted to showcase the property information within the td elements of a tbody. I am aware that v-data-table components have a ...

Need assistance with the Angular polyfill.ts file? Wondering where to place the polyfill code and how to manage it effectively?

Currently encountering an error in my Angular project that requires some 'polyfilling'. Due to the restriction on editing webpack.config.js directly, it seems necessary to work with the polyfill.ts file instead. The issue lies in the fact that An ...

Guide on making a loop inside a JSON request object

I am faced with the task of generating multiple "items" for a json request. Here is an example of a successful request: customs_info = EasyPost::CustomsInfo.create( eel_pfc: 'NOEEI 30.37(a)', customs_certify: true, custo ...

Passing a custom data type from a parent component to a child component in React

I'm currently working on developing a unique abstract table component that utilizes the MatTable component. This abstract table will serve as a child element, and my goal is to pass a custom interface (which functions like a type) from the parent to t ...