0

import fs

fs = requier('fs')

fs index.d.ts I can see fs library but I can't use

Error in cmd

my problem if I write require cmd error also, after installed fs of npm install fs.

same error after install or before install fs

Omar
  • 109
  • 1
  • 5
  • 12
  • fs is a module that is part of NodeJS. NodeJS is server-side. Angular is a framework for creating front-end applications. Check this out: https://github.com/angular/angular-cli/issues/5324 – Wingnod Sep 08 '18 at 19:27
  • Okay how solve my problem , I wanna write json file – Omar Sep 08 '18 at 19:42
  • I believe this question would help: https://stackoverflow.com/questions/30288087/is-it-possible-to-write-data-to-a-locally-json-file-with-nothing-but-angular It's not possible to write static files to the file system using client-side code. You'll have to choose an alternative method. – Wingnod Sep 08 '18 at 19:45
  • Thank you , but can you tell me how to save data directly such as saveAs(ex.json); – Omar Sep 08 '18 at 19:53
  • I am seen ur link last 3 hour but is give me link I wanna directly to json file , I'm confused sry . – Omar Sep 08 '18 at 19:55
  • You can't write directly to a json file. That stack overflow answer explains the other options. – Wingnod Sep 08 '18 at 20:08
  • I have been searched of 4 days for your answer thanks you – Omar Sep 08 '18 at 20:10
  • can you tell me , other options ? – Omar Sep 08 '18 at 20:11
  • I would like to explain the other options to you, but that other answer already explains them in great detail. This is a duplicate to that question. I would not be able to explain it any better. – Wingnod Sep 08 '18 at 20:24
  • hahhaaha hahahah ty. – Omar Sep 08 '18 at 20:26
  • hahahahahah I do that and save data directly to json file + dynamically – Omar Sep 09 '18 at 06:54
  • You don't have more experience in Node.js with Angular 6 you need course to learn of me. – Omar Sep 09 '18 at 07:02
  • I'm not sure what you're trying to say. You were trying to use Node file system api to write to a json file, but in your answer, you are downloading a file that you received from your server. These are not the same things. – Wingnod Sep 09 '18 at 09:25
  • It seems I missed your comment about wanting to save a file as json. Sorry about that. However, I'm not sure that you really want to download the file onto the client machine, unless you expect the client to use the data for something. – Wingnod Sep 09 '18 at 09:31
  • No, problem pro, I'm just kidding! :D – Omar Sep 09 '18 at 10:06

1 Answers1

-1

I connect between Node.js with Angular 6 using file-saver

npm install file-saver --save
import { saveAs } from 'file-saver';


const jsonObject: object = {
      'City': [
        {
          'id': 1,
          'name': 'Basel',
          'founded': -200,
          'beautiful': true,
          'data': 123,
          'keywords': ['Rhine', 'River']
        },
        {
          'id': 1,
          'name': 'Zurich',
          'founded': 0,
          'beautiful': false,
          'data': 'no',
          'keywords': ['Limmat', 'Lake']
        }
      ]
    };


const blob = new Blob([JSON.stringify(jsonObject)], {type : 'application/json'});
saveAs(blob, 'abc.json');
Omar
  • 109
  • 1
  • 5
  • 12