Angular2 integration in the kernel and node.js file system

I study Angular2, Typescript and reactive programming. I wrote a simple Typescript application on NodeJs that controls the change directory (main OS and file system). In one file. here https://github.com/maroshi/nodejs-directory-monitor/blob/master/app.ts

Now I want to add an interactive GUI to it using Angular2. I want to integrate my catalog monitor as a service into an Angular2 application.

Questions.

  • Is it architecturally safe / correct to allow an Angular2 application access to the file system and OS (assuming it is a fancy NodeJs server)?
  • How to integrate NodeJs utility library fsinto Angular2 application.

I am using the Angular2 quickstart template from https://github.com/angular/quickstart .

I changed app.component.ts

import  * as FileSystem  from 'fs';
import { Component, OnInit } from '@angular/core';`

@Component({
    selector: 'my-app',
    template: `
        <h1>My First Angular 2 App</h1>
        <p>Some FileSystem info: {{dirInfo}}</p>
    `
})
export class AppComponent implements OnInit { 
private proccesInfo: string;
    ngOnInit(){
        let tmpString: string[] = FileSystem.readdirSync('/home');
        this.dirInfo = tmpString != null ? tmpString[0] : 'undefined';
    }
}

This compiles well, but does not load with errors:

GET XHR http://localhost:3000/fs 404 (Not Found)

Error: patchProperty/desc.set/wrapFn@http://localhost:3000/node_moduleszone.js/dist/zone.js:769:27
    Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:356:24
    Zone</Zone</Zone.prototype.runTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:256:29
    ZoneTask/this.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:423:29

    Error loading http://localhost:3000/fs as "fs" from http://localhost:3000/app/app.component.js

Please report this study.

Note that tsconfig.json is the default tsconfig.json from the link above. Compilation for NodeJs "module": "commonjs",

Thank you Joy and happiness

Dudi

+4
source share

Source: https://habr.com/ru/post/1650475/


All Articles