Managing ServerSide FileSystem through Web Application - javascript

I am developing a web application that will manage directories and files through its web interface.
Developing a web interface is one part, and it is in advanced progress. However, I start thinking, how should I develop the server application, that will manage the files and directories based on user input.
The client will be created using standard tools:
HTML5
CSS3
JavaScript
PHP - Despite it is server side application, it will be responsible mostly for Dynamic Websites
MySQL - Despite it is server side application, it will be responsible mostly for keeping information about users, their settings, etc..
Would you advise me please, what would be a server-side programming language of choice to manage server-side file system? Is there any API available, that will allow me to do exactly what I wish? Is it possible to manage the server-side file system in server-side JavaScript, or should I chose another tool? Server-side JavaScript comes to my mind as a logical chocie, as I use it for the client side as well.
This is what I wish to achieve:
To create new directories and files
To delete directories and files
To track the directory and file size
To move files between directories
To provide content of the directories and subdirectories
Ideally, the solution should be platform independent and should work on both, Linux Ubuntu and Windows Server OS.
I understand that my question is a bit broad. I would be thankful, if you point me to the right direction, which technologies to start studying, to be able to accomplish the above mentioned.
Thank you.

You already have a very capable serverside language in your list. PHP.
PHP can do all of the things you listed above... and a few you didn't list as well :)
To create new directories and files
New files can be created with the touch() function, and new directories with the [mkdir()](http://php.net/manual/en/function.mkdir.php function.
To delete directories and files
Deletion is done with rmdir() and unlink().
To track the directory and file size
File sizes can be monitored using the filesize() function. Couldn't find a native folder size function but this Stack Overflow post may be useful - https://stackoverflow.com/a/478161/558021
To move files between directories
Moving files and directories can be accomplished by using the rename() function.
To provide content of the directories and subdirectories
One of the functions PHP gives us to scan folders is called glob() it glob - it allows you to find pathnames matching a pattern, so if you give it a wildcard character * it will find all the files in a certain location.

Related

Should i include all my js files to one js file?

i am wondering if i have to include all my javascript files to one entire file which file included to a folder? I just have for example 10 seperate js files into one javascript folder is bad for the website? Or it is ok?
P.S.I am new one to web development.
Photo of my Folder:
If you're on a halfway decent server - one that can respond to clients in your service area quickly - it's unlikely to matter.
The biggest issue with including many separate files is that, if your server uses HTTP/1.1, clients will usually only be able to request a small handful of resources at a time (10 or less). If you have a whole bunch of resources that the client needs to download for the app to function, and the ping between the client and your server isn't great, this could increase the time it takes for your site to initially appear functional. But for only 10 script files, it's probably not an issue. (Look at many of the large sites of today, and you'll see that quite a few of them load a huge number of resources.)
If your server uses HTTP/2, clients will be able to download all files requested at once, without a limit on the number (except for bandwidth), so in that situation, using many different files is less likely to create issues.
Still, for larger applications, it could be a good idea to bundle up your script into a single file for production. There are many options out there, and they have a bunch of benefits - they're often considered essential for a modern application.
Ideally it is all in one file. On your development computer you will probably have several js files, especially as you begin including various js packages or frameworks to your web application (website). On your development machine, you can manually use a tool like grunt to automate the creation of that single js file from several different js files, or you can automate the build process and other pre-deployment tasks using a CI/CD pipeline.

JavaScript, Reading and Writing files for a locally hosted application

I have read several posts on this site that ask similar questions but the key difference is they involve a client and a server. For my use, this is not the case. I am simply pasting a file directory on my computer into my browser in order to view a local HTML file, packed with CSS and some jQuery.
I've been looking around and the answers I've found are "No; a client can not write to a server", and "No; a server can not write to a client". But there is no answer to "can a client write to a client with JavaScript?"
Use case:
I'm building a webapp (website? JS app?) as a college project for a stock management tool that will be locally hosted and never connect to the internet. Sure, I could knock one together in python in a couple hours, but I wouldn't learn anything. I need to create an access a txt file containing an array of the current stock of all the items so that when the application is loaded, the user doesn't have to manually enter anything but the changes to stock levels.
Honestly, I'm a beginner at JS and JQ and I'm only going off of what makes sense based on a mix of HTML and Python that I know.
Maybe PHP would be the better option for this particular option, or maybe JS will work well enough.
You still won't be doing client-to-client, your browser will just act as though the local file system is the server using the file:// protocol which means the same rules about a "client" (the browser) cannot write to a "server" (your local file system) apply.
If you wan't to be able to write an application that can interface directly with the filesystem, then look into something like Electron which is essentially an augmented website that gives you APIs to interact with the actual computer the app is being run on, including filesystem stuff.

How to serve 2 different versions of websites under the same domain?

I have started working on a project that needs a re-write. So, instead of doing a big bang release
we have decided to use Strangler Pattern which means the following
The current application (stack details below) will be running as is under the existing domain https://app.com
The existing (and new) features will be re-written in a new stack (details below) and deployed in parallel to the existing app (under the same domain https://app.com)
The requirements are
The end-user always works with the same domain https://app.com
Any existing feature migrated to a new app or a new feature is available by the under the same domain https://app.com
The stack and architecture of the current app is
HTML files with hardcoded data
CSS files
font files
PDFs
images
flash files
among other things.
Thee application is static. It has no database. It makes calls to other 3rd party APIs but does not have its own database (other than the files, and the images)
It sits under a directory and is served by running a web server (Apache) on a private dedicated server.
The stack and architecture of new re-write will
Use React or Gatsby
A standard build system that generates the static files
The data (PDF, Images) hosted somewhere else
Flash files (until we figure out a better way)
Given these requirements, I thought of having 2 versions of the app using some sort of load balancer such as Nginx and serve the URL patterns using a proxy.
For example
a request coming to https://app.com/productPage.html goes to existing app deployment (assuming it is not migrated)
a request coming to https://app.com/profilePage goes to existing app deployment (assuming it is migrated)
Now, considering this situation, I want to ask the following question
Is this approach looks sane? Are there better ways to deal with this situation?
How to implement such a reverse-proxy based system (considering Nginx)? (or if there is a better way)
I would love to hear out ideas and any resources/books/github that can help me learn and implement this.
Thanks a lot in advance!
I would recommend to create a v2 of pages that has been migrated to new functionality. And all links to the page should be updated to point to v2.
If anyone has done bookmark to old links, then those pages can simply redirect the user to the v2 ones by simply redirecting them using JS - window.location(url_of_target_page);

How to manage multiple deployments of a JavaScript Web App

I have a JavaScript web application that we are offering to customers using a SaaS model. Right now, the application consists of several HTML files, JavaScript files, CSS files, and image files as well as a single proxy page (ashx file) with a config file. We have deployed the app on GoDaddy's shared hosting service.
We currently deploy an exact copy of the entire app folder structure for each customer and I am quickly realizing that this is a nightmare in terms of maintenance when I need to provide an update or bug fix. I have to make the change to every instance of the app for every customer.
Is there a better way to handle this? I've heard of using a single code base with multiple config files for dynamic apps built on server-side technologies like ASP.Net or PHP, but I have no clue how I can do this with JavaScript, especially since the HTML pages need to be slightly different for each customer.

List files in a directory using only javascript

Is it possible to list the files in a directory using only javascript? To clarify, I mean list the files on the server, not the files on the clients computer. For instance:
www.domain.com/files/
contains 4 images (.jpg)
Can I make an extra page (www.domain.com/files/list.html) that lists those 4 files using javascript?
No, Javascript doesn't have access to the filesystem. Server side Javascript is a whole different story but I guess you don't mean that.
Very late to this party, but my google search for this exact request led me here.
The answer is "not really", but I've found the frankenstein of hacks elsewhere: If +Indexes is (or can be) enabled in the .htaccess for the folder containing the files you want to list, then use XMLHTTPRequest with the folder name as the url (which will return an html page listing the files).
I don't know if you architecture allows it but ikf you can install and use node.js as its node API mentions, you can interact with the filesystem by requiring the fs module.
This is the environment Node.js relies on:
Node eventually wants to support all
POSIX operating systems (including
Windows with MinGW) but at the moment
it is only being tested on Linux,
Macintosh, and Solaris. The build
system requires Python 2.4 or better.
V8, on which Node is built, supports
only IA-32 and ARM processors. V8 is
included in the Node distribution. To
use TLS, OpenSSL are required. There
are no other dependencies.
You can run It side-by-side with another web app. and this will avoid blocking your web application if the interaction with the filesystem takes too long.
It is generally not a good idea to access client computer files via javascript for security reasons, however i suspect you can use the File System Object for that. I am not sure about browser-compatibility for that, it should work in IE only probably though.
You need to use server-side languages such as PHP, ASP.Net, JSP, etc
JavaScript runs inside a host environment. So if the host provides a facility to list files in this manner, then yes. But in the typical scenario where JavaScript is running in a browser with default configuration, no.

Categories