I need to be able to start my Node app, that is using Sails from another working directory:
The usual: node app
What I need: node myfolder/app
The second way lifts the server, however, none of the assets works. Looks like he is using my current directory as the assets folder (didn't tried api or anything else), but the server get's lifted.
What happens, is that accessing resources, gives me back a Not Found.
Is this a issue, or am I doing something wrong?
Explaining my goal:
I have a folder with multiple node apps. I'm using pm2 to launch lots of processes, so, my folder structure is like this:
Apps
|- processes.json
| App1
|-...
| App2
|-...
I need to start all the apps from the Apps folder, not from within the App1 or App2 folder. However, it is not working properly with Sails.js. I have tried to run only a single app from another working directory, but the same problem occurs.
Actually, a better answer if you're going to be running things through a process manager would be to change the directory in the Sails app's main file itself. That is, at the top of the App1/app.js file, put:
process.chdir(__dirname);
that way you won't be starting a different process, and the process manager will be able to monitor output, logs, etc. in the expected fashion.
Not sure if this would be a good thing to have in Sails by default, but we'll look into it!
Sails does expect you to be lifting the server from within the app directory. However, you can always write a wrapper script to temporarily change the working directory:
process.chdir('App1');
require('child_process').exec('node app.js');
Save that in your main Apps directory as runApp1.js, and use your process manager to run that instead.
Related
I develop a nextjs application. Inside the root folder, I've made landing/pages/ folder and I want to run dev server with those pages using next dev ./landing. The point is to create a separate app using the same codebase, configs, etc.
Dev server runs properly, but most features don't work:
.env is not read from the root folder (the workaround is to use cp .env ./landing && next dev ./landing). but it's an ugly way to solve it
assets are read from public folder inside the /landing. But I'd like to use the public folder from the root.
I can't use components from folders that are "above" /landing folder in the project structure. The compiler throws an error You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.
Is there any custom configuration to solve the problem? Maybe there is another way to have something like two "pages" folders in which there is the same source code, but thanks to it I could build two separate apps?
I've pushed my current code to the following repository:
https://github.com/michalgrzasko/nextjs-2-pages-example
Just run dev server using yarn dev. To reproduce errors:
Uncomment process.env.NEXT_PUBLIC_APP_BASE_URL in landing/pages/index.tsx
Uncomment <Nav /> component in the same file
.env is not runnable files, if you will load from "somewhere" - you don't need it.
You should focus on the next.config.js file.
Check this, maybe will help.
Anyway, you will need:
-API from your second source(from where you like to load config)
-Load config every time once you dev build your project.
-use process.env.your_name in your classes/functions
I have created the project using npx create-react-app my-app https://github.com/facebook/create-react-app.
When running npm run build I get the following:
70.28 KB build\static\js\2.93539f7c.chunk.js
22.82 KB build\static\css\main.cfe0ffe9.chunk.css
1.41 KB (+44 B) build\static\js\main.79f4d9a1.chunk.js 761 B build\static\js\runtime~main.fdfcfda2.js
The project was built assuming it is hosted at the server root. You
can control this with the homepage field in your package.json. For
example, add this to build it for GitHub Pages:
Looks like I need to have server to run the app.
Is it possible to run this locally without any server running? I mean since it is just html,css,js and why would a server be needed here? for what purpose?
Also there is many files generated into the build folder, there is an index.html too, a static folder, so its not like a single bundle.js and a single index.html, it seems more complicated.
Anyone can explain why the build folder is this much files? and which one to consider for running the app?
Thanks
Is it possible to run this locally without any server running?
No
I mean since it is just html,css,js and why would a server be needed here? for what purpose?
React loads content using XHR, which can't make requests to file scheme URLs.
Anyone can explain why the build folder is this much files?
React makes use of code chunking to optimise which data is loaded. This means that JS which isn't used immediately can be loaded later on and not impact the time between initial page load and first render.
By default, Create React App produces a build assuming your app is hosted at the server root.
To override this, specify the homepage in your package.json, for example:
"homepage": "http://mywebsite.com/relativepath"
This will let Create React App correctly infer the root path to use in the generated HTML file.
source: https://create-react-app.dev/docs/deployment/#building-for-relative-paths
So you should just specify your homepage as the current path:
"homepage": "./"
It's my first time I'm trying to do that.
I'd like to set up config file in circle.ci in order to deploy my React app to expternal server. Before I just used Ftp connection to upload files to the production server. But now I'd like to do that authomatically. So in my circle config file I've already configured steps to run yarn install and yarn build, all is just doing fine, but the last step needs to be done, I basically have no knowledge how to connect it all, ie. files comes from github, then they are used for build purpose by circle.ci, then I'd like to deploy it to the production server. What is the flow here, and what should I use (ssh somehow, but how?). Thanks
If you're hosting provider supports it, I would suggest using rsync over FTP since it will ensure files are replicated without needing to upload everything, only changes. The --delete option will al\so remove extraneous files on the webhost that you may have removed from github.
- run:
name: Deploy public folder to YOURDOMAIN
command: |
rsync -avz --delete /local/path/ USERNAME#HOSTNAME:/Path/on/remote/server/
if yo have not made any changes to default CIrcleCI images, your local path is likely /home/circleci/project/
I am using angular4. I used angular-cli to create my project.
I want to use node.js as server side language with mongodb. So, I found a tutorial here to connect node.js with angular.
But there are two problems with it:
dist folder is created.
auto refresh server like using nodemon or similar is lost
problem with dist folder
My site depends heavily on images. I keep all the images in a folder called images which is located under assets folder created by angular-cli
So, when I run the server, all the assets will be copied to the dist directory, which will take time and (more important) space on the webserver. Another problem is that If I upload new images, then it will be copied to the images folder inside dist folder, so I have to manually copy those images to my original dist folder.
Another copy of images folder in dist folder will take double space than my original app. So, I have to pay more money for hosting to use more space.
problem with auto-refresh server
before using node, I just typed this command
ng serve
and my application started. Then when I change any code and save the file, the changes were reflected in the browser without restarting the server.
But when I started to use node, I have to manually restart the server whenever I make changes to my code.
Question:
Is there any way that prevents app to create images folder inside dist folder to save space. I mean can I use original Images folder instead of creating one inside dist?
Or is there any other way that a node application and angular application work together?
If anybody knows a solution that does not use dist folder, then I would love to use that solution. As my need is satisfied. Auto-refresh server is not important to me in this case.
So, if anybody knows a way of how to create a mean app without angular-cli,
then I think that is very near to my solution.
You can change dist folder's name to any name you want. you just need to find file .angular-cli.json in your main root folder and change json
"apps": [
{
...,
"outDir": "dist", // dist to any name e.g. public, ...
...
}
]
I have a nodejs application using hapi.js and I'm trying to download an image from a url. Heroku is giving me errors with the pathing.
My code:
Request(uri).pipe(fs.createWriteStream(__dirname+'/../public/images/'+filename)).on('close', callback);
My errors:
Error: ENOENT: no such file or directory, open '/app/../public/images/1430540759757341747_4232065786.jpg'
My file structure is simple:
app.js
-public
-images
-sampleimage.jpg
-videos
-samplevideo.mp4
-audio
-sampleaudio.wav
As you can see the __dirname for heroku application is /app. I've tried using __dirname+'all sorts of pathing ../ ./ etc' and I've also tried it without __dirname.
I will be creating a lot of these files using ffmpeg and a speech tool. So could anyone explain to me what kind of problem I am having? Is it something that can be solved by using the correct path name or is it my hapijs server configurations that I need to configure?
You just have the wrong path in your project.
On Heroku, you can't write to the folder BELOW the root of your project.
In your case, your code is running in app.js, which is in the 'root' folder of your project.
So, on Heroku's filesystem, this means your project looks like this:
/app
/app/app.js
/app/public
/app/public/images
...
Heroku puts all your code into a folder called app.
Now, in your code pasted above, you show:
Request(uri).pipe(fs.createWriteStream(__dirname+'/../public/images/'+filename)).on('close', callback);
If this code is running in your app.js, it means that by going BACK a folder (eg: ..), you're trying to write to a non-writable part of Heroku's filesystem.
Instead, you want to write to:
Request(uri).pipe(fs.createWriteStream(__dirname+'/public/images/'+filename)).on('close', callback);
This will correctly write your file into the images folder like you want.
HOWEVER
Here's where things are going to get complicated for a moment.
On Heroku, you can indeed write files to the filesystem, but they will DISAPPEAR after a short period of time.
Heroku's filesystem is EPHEMERAL, this means that you should treat it like it doesn't exist.
The reason Heroku does this is because they try to force you to write scalable software.
If your application writes files to your webserver disk, it won't scale very much. The reason why is that disk space is limited. Each web server has its own disk. This can lead to confusing / odd behavior where each webserver has a copy of the same file(s), etc. It just isn't a good practice.
Instead: what you should do is use a file storage service (usually Amazon S3) to store your files in a central location.
This service lets you store all of your files in a central location. This means:
You can easily access your files from ALL of your web servers.
You can have 'reliable' storage that is managed by a company.
You can scale your web applications better.
The folder you hosted on heroku is considered as "app" which you can see from the error you got. I m commenting this after 5 years just to let future viewers know. If any folder is empty, it is not pushed to github or heroku when you pushed the entire project as the folder is empty.
When we try to access a folder which is empty initially, we get the above error as the folder is not pushed in the first place. So, if you want to get rid of the error, place a temp file of any type ( I used a txt file) and push the code. Now the error won't be there anymore as this time the folder is pushed and it can access it.