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

15
  • 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: github.com/angular/angular-cli/issues/5324
    – Wingnod
    Sep 8, 2018 at 19:27
  • Okay how solve my problem , I wanna write json file
    – Omar
    Sep 8, 2018 at 19:42
  • I believe this question would help: stackoverflow.com/questions/30288087/… 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 8, 2018 at 19:45
  • Thank you , but can you tell me how to save data directly such as saveAs(ex.json);
    – Omar
    Sep 8, 2018 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 8, 2018 at 19:55

1 Answer 1

-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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.