Auto read local file with html js or reactjs framework - javascript

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

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.

Related

Is it possible to get pages from remote file system with next.js

Hi I am quite new to advance frontend technologies and I have simple question.
scenario
I would like to use next.js and its feature: server side rendering.
I would like also to have my js, css and html files stored in outside of host machine where next.js is running. I want to have my files in azure blob storage. It is neccessary because I would like to have many SPA pages and single wwwroot directory is not enough for me.
Problem
By default next.js get its files from pages directory at host machine.
Is it possible to tell next.js to get files from other file system etc. In this scenario it would be azure storage. I could not find any example or extension point to do that.

Developing Less CSS locally without a server; "no sheets were loaded"

So I'm trying to extract my own CSS framework from my projects so I can develop it separately.
I have my index.html with less.js and included my main .less file which #imports a dozen other files...
However, in the console I get an error for each of my less files:
Resource interpreted as Stylesheet but transferred with MIME type text/plain: "file:///path/to/project/src/file.less".
And a final line that says Less has finished and no sheets were loaded.
So I understand this to mean they aren't being served correctly, I normally use Node.js/Express, but I don't want to include all of that in my repo just to develop some CSS. How do I get around this?
I thought about using some node package like serve for development but I feel like this shouldn't be necessary.. Unless I'm wrong?
EDIT: here's my repo, https://github.com/kenmorechalfant/framewerk
Don't use file://. You're going to run into a mountain of XSS errors. Just use a quick static HTTP server. I use http-server with node and most IDEs have one built in. It is going to be more trouble that it's worth to try and not use a static HTTP server if you don't have a good reason not to.

How to read (text) files using NodeJS

I am working on a project using AngularJS and NodeJS. I am new to both frameworks and need some help for reading in (text) files.
I am trying to read files using npm's read-file (https://www.npmjs.com/package/read-file).
I put var read = require('read-file') into one of my controllers Javascript files, but I keep getting an error message Cannot find module 'read-file'
Below is the current project structure:
my_project
|--app
|--bower_components
|--components
|--scripts
|--controllers
|--my_controller.js
|--styles
|--views
|--my_page.html
|--app.js
|--index.html
|--node_modules
|--read-file
|--index.js
|--LICENSE
|--package.json
|--README.md
Clearly I installed the read-file module, but I think there is an issue locating it. What should I do to make sure that require('read-file') correctly locates the read-file module?
Any help will be appreciated. Thanks!
It seems that you are trying to read the read-file module within your Angular.js application controller. The controllers within Angular.js are front end files and are run from within the Browser environment and not Node.js. Therefore, you cannot use utilities such as require within the browser.
I think you may be able to achieve what you are trying to accomplish by running your front end application through a tool like Browserify. This will allow you to use Node.js to do stuff like require which will load the file during compilation time and allow you to require files within the browser. You can also use Node.js tools such as fs to load the contents of files and include them within your front end application. I think this should get you pretty close.
I think you are trying to load the read-file module in the client js part, where is not defined at all.
You should create your node server here, and create an api you should call from your front-end controller that load get the file.
From the node api handler you read the file and send back to the client when requested.

Install files to sdcard on Android/IOS with phonegap

I have some files that I need to copy to a folder once the user has installed my app. I was trying to find a way to transfer the files directly from the application root directory but no luck. I had also seen a suggestion about zipping the files and including the zipped file in my package, then extracting them to the folder. But did not know how to implement either methods.
Another alternative is to download and install the files when the app starts, but didnt want to rely on having to maintain the files on a server or that the user always has internet access since my app can be run offline.
How do I do this with a Phonegap/JQM/Javascript app?
Thanks,
Robert

Can i run a php file or a html file in a node js web server?

Maybe it's a stupid question but i am a newbie using node js, and I think that it can be used just with js files, I dont know, I installed node js on my windows and i started the web server but i dont know how to run the files, I have always worked with apache, I saw there is a folder called scrips in the node js installation folder
but i dont know how to run the files, I have always worked with apache.
In NodeJS, it's either you write the web server (it's like writing Apache itself), or use a framework that does it for you (it's like adding in something like Apache). Suggesting you check out Express. It's something almost close to CodeIgniter (writing points of entry).
Can i run a php file or a html file in a node js web server?
NodeJS is for JS. Your server files are all in JS. As for HTML, checkout Express (mentioned above), or if you just want to serve plain HTML (or static files), you may want to check out Connect Static

Categories