L
L
Leonardo-lavanda2019-08-16 14:15:16
Node.js
Leonardo-lavanda, 2019-08-16 14:15:16

Why can't work with the file system on node js?

I work with create-react-app, when I try to create, read and other operations with files, it generates an error:
5d5690c70650d840743735.png

import React from 'react';
import './App.css';

// components 
import Sidebar from './components/Sidebar/Sidebar.js'


// data
let webComponents = require('./data/web-components.json');

const fs = require('fs');

console.log(fs);


setTimeout(() => {
  webComponents.push({'text': 'четвертый', 'isActive': false});

  fs.readFile('./data/web-components.json', 'JSON.stringify(webComponents)', () => console.log('ok'));
}, 4000);

class App extends React.Component {

  constructor() {
    super();
  }
 
  render() {
     return (
        <div className='App'>
          <Sidebar items={webComponents} />
        </div>
      );
  }
}

export default App;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Zhivagin, 2019-08-16
@Leonardo-lavanda

A simple web server is launched in the node, which gives the react application to the browser.
React runs on the client, it has nothing to do with the node.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question