MSKH
MSKH

Reputation: 53

What is the best module or solution to upload images for React and Node Js

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

Answers (1)

Quentin
Quentin

Reputation: 943663

File uploading requires two pieces of software.

  1. A client to upload from
  2. A server to upload to

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

Related Questions