Reputation: 53
I was trying to implement upload image functionality in a form, using this as an example. It was working till I reached the part let fs = require('fs');
where i encountered the following error "Module not found: Error: Can't resolve 'fs' in...".
There is a thread on stackoverflow, mentioning the solution for it to use "target": "node"
which does not apply for me as I am building a web application.
So I was hoping If someone can point me in the right direction; and let me know which is the proper or the best way to implement image uploading in forms, as I am new to Node JS, and running into errors I can't find solutions for.
Upvotes: 0
Views: 182
Reputation: 943663
File uploading requires two pieces of software.
You are building your client with React and running it in a web browser.
It sounds like you are using Node.JS as a transpiler for that.
You also need a server. The error message you get suggests you are attempting to run the server side code (which, in the tutorial you link to, uses the fs
module that comes with Node.js) as part of your client.
This won't work. You need an HTTP server to upload the files to (which could be written in Node.js or could be something else: The tutorial you are using uses Node.js).
Upvotes: 1