Answer the question
In order to leave comments, you need to log in
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:
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
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 questionAsk a Question
731 491 924 answers to any question