1

I have researched for many hours to find the way to auto read local file with html and js , but the only way is create input tag in html but user need to select file in their computer and read it - this way doesn't auto read (I use http-server command to run html file).

I know direct access "file://" is blocked by browsers for security reasons or some solution like "--allow-file-access-from-files"

But when i use reactjs and read file from public folder, it's work (app create by npx create-react-app )

Could you tell me the difference between them and give a solution to auto read local txt file with only html,js.

Sorry for my bad English.

Thank you very much

1 Answer 1

1

create-react-app is just serving your local files via Webpack, it is the same as using Nginx to serve your local files or using Apache. When you create a build using webpack you are merely guiding your server to serve static content at a particular host.

You may want to refer to Nginx and Express and read how they work.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for fast rely, what about http-server to run localhost:8080, does it serving my local file, and why I can't read my local txt file via html,js file.Can you explain it to me
It depends upon the loader, for example, you may very well ready your CSS and HTML just like that you will need a loader for your type, in your case your can use webpack's raw-loader webpack.js.org/loaders/raw-loader

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.