nodejs create/delete local file on windows azure website "local storage" - node.js

I created a generic nodejs/expressjs app and git deployed to windows azure website (not web role, or virtual machine).
The folder structure is typical of an expressjs app:
app.js
package.json
routes/
public/
views/
node_modules/
temp_data/
The app can happily create and write files to the temp_data/ folder using nodejs fs.writeFile('temp_data\\temp_file',...,).
These can't be called "local storage", and not sure about the life time of these files. But as the names pointed out, they are temporary files.
The question is that when I tried to delete these files using nodejs fs.unlink('temp_data\\temp_file',...), after fs.exists('temp_data\\temp_file',...), it failed.
Is that because I have permission to write a file, but no permission to delete a file from a deployed folder?

Related

Configuring .htaccess for React+Vite in Cpanel

I created a project in React.js and Vite.js and I want to deploy it using CPanel, but when get the content of the dist folder out to the root the app doesn't get .env variables, so I figured out that I need to keep content of dist folder inside of it and create .env outside for the app to recognize it.
But I couldn't figure out a way to configure .htaccess file to reference the files inside dist.
folder structure I have in Cpanel file manager
dist
| |___assets
| |___index.html
|
|__.env
|__.htaccess
I need some help please to get .htaccess to work or .env to be recognized

Nodejs ready file name from path

I've used FS library to read the file inside a directory, if running in local, this Is ok. But if deploy my app on Cloud, as Heroku, how can I read the file in local machine from a path?
Thanks a lot

Hosting Multiple react app in cpanel on singe domain

I had delveloped an react application which I want to upload it to cpanel. I had my website also running on the same domain.
Example:
https://www.mywebsite.com host my web content for selling roses.
Now I want to upload my application(APP1) developed in node js as backend and reactjs as front end.
But in future I need to upload similiar other websites too. So I want to create a folder on root and inside or the root i want to upload my application (APP1).
In future if I develop another application(APP2) I want to upload it to same domain in another folder on root (APP2).
My folder structure will be as
Root
...WEBSITE FILES
...APP1
......app1_files
...APP2
......app2 files
Now how to deploy my APP1 and APP2 on my domain.
Go to the 'package.json' file in your React Application, add a package name ("homepage": "YOUR WEBSITE LANDING PAGE LINK")
Screenshot
Go to the terminal of your editor and type "npm run build".
Navigate to the Application folder, you will find a folder named "build", upload all the files to the website directory.
HOW TO MAKE A DIRECTORY?
Go to your cpanel > public_html (this will be your root folder): you can upload your files here.
If you want to make a directory or another application within the same domain just make a new folder inside public_html and upload the application within that folder and the application will be available by typing: YOURWEBSITE.COM/FOLDERNAME

Folder structure to deploy app on EC2 instance

I am setting up a new React app on EC2 instance (ubuntu). I have installed nodeJS and npm and I am able to build my app successfully.
Issue is my code is in /var/www/html folder and my site example.com is pointed to this folder.
when I run
npm run build
It builds a folder under /html like /html/build now my app runs on example.com/build. Resources for these files comes from example.com/static/style.css etc but they actually reside under example.com/build/static
I can edit asset-manifest.json and change the path but thats not appropriate solution as I need to get rid of /build folder for production
I am not super familiar with deployments to EC2 but this looks like you just need to either copy the entire contents of your app inside var/www/html, or you need to tell apache or nginx to look to the right folder (in this case /build)
For example, with apache you probably have a file inside /etc/apache2/sites-enabled/ that is pointing to /var/www/html, you could change that to /var/www/html/build and restart apache.
You can check this for examples on how to write these configurations https://gist.github.com/rambabusaravanan/578df6d2486a32c3e7dc50a4201adca4

In Azure, What is the difference between wwwroot and repository?

I recently started to make my website and found interesting thing. I spent like 30 mins to modify my index page but it didn't change somehow. And then I found out index.jade is the one in wwwroot folder, not repository folder. I compared these two folders and it has no difference at all. They both have same jade files.
I wonder what is the purpose for each directory? What wwwroot directory for and what repository directory for?
When I tested, there is no change in "actual website" when I modify index.jade file in repository directory. But actual website changes when I modify index.jade file in wwwroot folder.
Thanks in advance.
When you provision a webapp in Azure appservice you will not have repository folder by default. When you enable deployments (like say Local Git Repository) then repository folder is created. wwwroot will be there by default and is the right location where the actual content is served by the webapp. Repository is where you can push your code (through git push) from local git repo to azure remote and will be first staged in "repository" directory and deployed to "wwwroot" but i don't think if you change/upload/ftp the files to repository it won't impact anything unless you either copy to wwwroot as well (or deploy code through git push to remote). so in short wwwroot is where the content is served by your web server and repository is where the code is managed/staged for fetch/push.
https://azure.microsoft.com/en-us/documentation/articles/app-service-deploy-local-git/

Resources