Problem with Parse Server vs Oracle Cloud - node.js

I've spent the last 3 days trying to make a Ubuntu Oracle Cloud VPS a parse server (Yes, I know services like Google Firebase and Back4App but my website consume a lot of requests by a user/hour and I don't have money to spend right now), so I followed this tutorial:
https://dev.to/autodidaktum/how-to-deploy-parse-server-and-parse-dashboard-on-digital-ocean-2021-3o5h
I have followed every step just changing little things like node version (I got the most updated) and didn't create a network domain.
Everything ran "ok" (I had to install some packages and force the parse-server download) but when I reached the "Install Parse Server", the last part of it says to run npm index.js but npm returns with something like: "execute npm run lint", sounded really ok to me but when I ran it, returned me the message:
parse-server-example#1.4.0 lint
eslint --cache ./cloud && eslint --cache index.js && eslint --cache ./spec
and no reach from my browser from "{ip floating address}:1337" (yes, I know that {ip floating address} means the external IP), so I thought I was missing to open a port for access in both areas like inside the server and the Virtual Cloud Network, I opened them (images below) and still no reach.
I let it go and went to the "Install Parse Dashboard" step and started the server, nice message
The dashboard is now available at http://0.0.0.0:4040/
another browser test and still no reach. (obviously, I have tested with externalIp:4040)
The real question is, I did something wrong based on this information?

Related

ENOMEM error when starting Next.js app on shared hosting server

TL;DR: I got an spawn ENOMEM error when trying to build and run my Next.js app on a shared hosting server, which had over 900MB RAM and 70+ processes available at the time this happened. The log showed that the RSS size was 50814976 when the error was caught.
I am not quite sure if the error is simply caused by insufficient memory or it occurs because of incorrect settings or configs. Could you please give me some advice?
==========Details below============
I am building a Next.js app with Node.js, and it’s built with a custom server (my entry point: server.js). I can run my app in a local environment on localhost:3000. Then I try deploying it to check if it’s ok on the network.
I have subscribed to A2 Hosting’s DRIVE Web Shared Hosting Plan, which is optimised to support Node.js environment. What they offer in the plan are 1GB of physical memory and 75 available processes.
My application was created through the Setup Node.js App function on the cPanel, and cloned my project into the server with git via SSH. NPM packages were also installed on the server with the command npm install. The node version was v.12.9.1 and npm version was 6.14.8.
My npm scripts were defined to run the custom server. Here were the npm scripts defined in my package.json file:
"scripts": {
"dev": "node server.js"
"build": "next build",
"start": "NODE_ENV=production node server.js"
}
Then I used the command npm run build to create the production application in the .next folder, but an error spawn ENOMEM came up immediately.
I googled that it was a memory usage related issue. Some said this error occurred when memory was not enough, and the workaround to bypass this was to build the production folder locally and upload it to the server. So I copied the steps.
However, the result was frustrating when I ran the command npm run start. The error ENOMEM was still here, coming up in less than a second after I entered the command.
Cleaning the npm cache and reinstalling the npm modules didn’t seem to work either.
I tried increasing the memory limit by adding option --max-old-space-size in the command and ran NODE_ENV=production node --max-old-space-size=1024 server.js; but unfortunately this didn’t seem to work and the ENOMEM still popped up.
I added console.log(process.memoryUsage()) to show the usage when an error was caught and this was the result:
{
rss: 50814976,
heapTotal: 34107392,
heapUsed: 23076064,
external: 1632450
}
The total rss size was far less than the limit. Or did I use a wrong method to inspect the memory consumption?
How can I solve the ENOMEM problem? What exactly the error is caused by? Is it really just because the available RAM doesn't meet the requirement of a next.js app?
I am not sure if I have applied incorrect settings, overlooked some important configs, or miswritten any codes that bring about this error. I want to figure out what is going on underneath. Upgrading the plan impulsively without adequate understanding isn’t good for me as a newbie developer, and it's my responsibility to make good use of the budget.
Could you please give me some advice?
Thank you for your attention.

First attempt at AWS Amplify with NodeJS gives 404 page not found

When go to the url given, something like this: https://master.xyz.amplifyapp.com/, I get 404 page not found. I don't need my own domain for this proof of concept. I also tried https://master.xyz.amplifyapp.com/poc (see my directory structure below). Same result.
Previous steps taken:
The directory was originally created by doing a clone of an empty AWSCodeCommit repository.
I ran create-react-app poc, and when I do npm start in the "poc" directory, it shows fine in the browser with this url: http://localhost:3000/ (Note at bottom of this post, I did the same thing with a NodeJS RESTAPI and got the same result).
This is my directory structure, and from there I did:
git add -all
git commit -m"first checking"
git push
In AWSCodeCommit I can browse the repository and see the code there.
This is the result of connecting CodeCommit to Amplify:
I'm expecting to see the same thing from the provided URL (https://master.xyz.amplifyapp.com/) as I do on my local machine (localhost:3000).
I had one idea. I copied the poc directory up to the main directory, committed, pushed, saw it rebuild/deploy, and tried again, but same result.
NOTE: I have gone through the same exercise with a simple NodeJS REST API. It also gets the "page not found".
Local: http://localhost:8080/api/books
returns: [{"title":"Harry Potter","id":1},{"title":"Twilight","id":2},{"title":"Lorien Legacies","id":3}]
With Amplify:
https://master.xyz.amplifyapp.com/api/books
gives "404 page not found".
I was thinking the problem with the React was that it was a regular React app, and not a Native-React application. But now I'm getting same issue with a simpler nodeJS application, and no idea what to try next.
This is the video that gave me the ideas to get it working, even though I'm not using Cognito. https://www.youtube.com/watch?v=g4qKydnd0vU
The first videos made no mention of installing and running amplify locally.
So I installed amplify on my Windows laptop. Then basically had to run these commands from the windows command prompt:
npm install -g #aws-amplify/cli
amplify configure
amplify init
When I ran the second command, it created another amplify app in AWS. Fortunately, my first project had dashes in it, and this one did not, so they didn't conflict. (I will go back and either delete my originals or try to get them working later).
Many of the videos demonstrate with GitHub, but I was using CodeCommit.
If you get an error in the Build phase that says "The requested URL returned error: 403", that means there is an access issue to your code library. I solved that by changing the "Service role" of my Amplify app to one that I created previously. If you respond with comments to this answer, there's a good chance that I won't have any answers.
amplify configure:
(I used an existing username that I had already created for the first attempts. If you haven't done that, I think you would need to do it so you have the data to paste in for user, access code, and secret.
amplify init:
So this is what I did to get it up and working (for both React and my NodeJS api backend). I have much more reading or watching videos and experimenting ahead to learn more about it. There were many videos that created the apps in the AWS web console, without using the command line "amplify config" and "amplify init" commands. Nobody answered this question for about 4 days, so it seems like maybe it's still new and not so popular yet.
I'm still having a minor issue on the NodeJS api/backend that I will figure out next. For this url: https://master.xyz.amplifyapp.com/api/books/ it returns:
<Error>
<script/>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>1Z3T564T3SSGXJQE</RequestId>
<HostId>mx8RKnqMS1MDe0oOiZ0it3A1sL0bRXHsdZrL5IBuin9S2llrwLFNI+y=</HostId>
</Error>
This is possibly indicative of a "page not found", and needs redirects to solve as discussed in this StackOverflow. The NodeJS code is a simple example that does this:
app.get('/api/books', (req,res)=> {
res.send(books);
});
I did the following which caused another build/deploy, but access denied error is still happening:
git status (I see new Amplify folder)
git add --all
git commit -am"after amplify config/init"
git push
My package.json contains this, among other settings:
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "node index.js",
"prod": "node index.js"
},

Vuejs and Nodejs deploying to heroku: $ npm run dev works but not $ node server.js

I made a website with Vue.js and included Snipcart API for a buy button. I've been trying to deploy it to heroku for 2 days now.
When I enter $ npm run dev it works fine and will display my web app. But for some reason if I do $ node server.js it shows the default Vue welcome page for its webpack ("Welcome to Your Vue App").
I've tried entering "start":"npm run dev" in my package.json but that just results in a forever loading web page. If I enter "start":"node server.js" It results in the same thing as the previous paragraph, it just shows the default Vue welcome page.
I found someone with basically the same issue (How to set up vue(2)-cli app to run with nodejs server) and even tried the same tutorial post but I don't know what that comment/answer is talking about. I am also unsure of how to deploy a static website with a Snipcart API (as a previous user mentioned to me in a previous post).
I am really at a loss as to what to do. Thanks for your time.
Edit: Here is the repo for my app: https://github.com/Taikon/MaroonRiver0
Exactly what I suspected in the comment: You are not building your assets.
Run
npm run build
node server.js
And it should work as expected.

Run node server and webpack together using package.json

I have completed todo app by learning from this video:
Super MEAN Stack Tutorial: Angular, Node/Express, Webpack, MongoDB, SASS, Babel/ES6, Bootstrap
In that video at time 19:18 at this url it is taught that I should use the below two commands in seperate git-bash instances if I want to run it in windows using npm run dev:
node server
webpack-dev-server --progress --colors
But in Linux (or any other OS than windows) you can use this script:
"Scripts": {
"start": "NODE_PATH=$NODE_PATH:./src node server",
"dev": "npm start & webpack-dev-server --progress --colors"
}
So, Is there any way I can do the same in windows?
Also, In that tutorial I can see that port no. 3000 is assigned to node server, but due to using dev dependencies he runs the localhost:8080 in browser. You can see that here. After the tutorial finishes, I followed along and created that app. Now I would like to deploy it. So, I would first like to learn to run test my site in non-dev dependencies mode. i.e. when I type localhost:3000 in browser, my app should run successfully. So, can anybody explain the steps for that?
Update:
I am a newbie in node.js. I watched many videos on node and tried to learn something from that. In all the videos I see that I run node server on port no. 3000 and then I type localhost:3000 in my browser. Now lastly I watched video about mean stack in which he uses webpack. Now, I am confused. I think there are two servers running. first server is webpack's server and second server is node's server. Upto today I typed localhost:3000 in my browser because I mentioned that port 3000 will be used by node in my code. But now in the video he is running localhost:8080 in browser. It means webpack's server is used. Then what happened to node server. Why can't I just run localhost:3000? Also in the video it is explained that webpack is a dev dependency. So, I think after the app is completed and ready to be deployed, my project can be run on the node server (by making some changes to the code, I am not sure). Let's take an example. Now I don't want to deploy the app to a real server. I want the same app to run on my friend's pc. He is not a developer. So, he should not depend on webpack as webpack is a dev dependency. So, he should be able to run the app on node server instead of webpack's server. So, he should type localhost:3000 instead of localhost:8080. That's what I don't understand.
Let's break this down:
If you've defined this script:
"Scripts": {
"start": "NODE_PATH=$NODE_PATH:./src node server",
"dev": "npm start & webpack-dev-server --progress --colors"
}
... then this npm command: npm run dev
... actually invokes these two actions:
a) npm start & # Runs NPM in the background
b) webpack-dev-server --progress --colors # Concurrently runs webpack in the foreground
You can accomplish the same thing in many ways using Windows, starting with a simple .bat file like this:
EXAMPLE: RunDev.bat:
start npm start
webpack-dev-server --progress --colors
=======================================================================
STRONG SUGGESTION:
Please forget about watching videos for a few moments. Try a couple of "hello world" tutorials. More importantly, play with the actual code. Try changing things in the code, and see what happens.
Forget about webpack, at least for the moment.
Think of npm as a "build tool"; not as a way to run your application. At least for a moment.
Focus on "node". Write a "node application".
Part of your "node application" will require "ExpressJS" and "Jade" (now renamed "pug" - I'm still using "Jade"). Use npm to get your ExpressJS and Jade dependencies, but stay focussed on Node.
SUGGESTED TUTORIAL:
A Simple Website in Node.js, Ben Gourley
Be sure to:
a. Download the code
b. Work through the tutorial, using the downloaded code
Please post back (a new post) with any specific questions you might have as you work through the tutorial.

How to correct a Bluemix Node.js app that can't accept connections

I created a new Node.js app on Bluemix this morning and downloaded the boilerplate code. I worked on it locally and then pushed it up. On Bluemix, it refuses to start. The error according to the logs is:
Instance (index 0) failed to start accepting connections
So I Googled for that, in every case where I found the result, the answer was that my application was trying to use a specific port instead of letting Bluemix set it.
Ok, but I'm setting the host/port with the exact code the boilerplate uses:
var appEnv = cfenv.getAppEnv();
// start server on the specified port and binding host
app.listen(appEnv.port, function() {
// print a message when the server starts listening
console.log("server starting on " + appEnv.url);
});
So if this is incorrect, it means the code Bluemix told me to download itself is incorrect as well, and I can't imagine that is the issue.
To identify whether cfenv is at fault, I've tested that piece of code with a number of more complex Node.js apps I have, and they work perfectly on Bluemix.
That message can also come when an application you've deployed to Bluemix fails to start at all. Here's a few things you can do to troubleshoot your Node.js application on Bluemix.
Tail logs in another terminal while pushing with "cf logs
". Inspect logs after the failure to see if something
failed during the staging process.
Check that your start command in one of two recommended places, scripts.start in package.json or in a Procfile with web: node <start-script>.
Check that your application works locally. First (optional), create a .cfignore file with "/node_modules" in it, so that when you push the app to Bluemix, CF CLI doesn't push your entire folder of node_modules (as they will be installed dynamically). Next, wipe out your node_modules directory and do an npm install --production followed by npm start (or your custom start command). This is what Bluemix does when trying to start your application, so you should double check that it works locally.
Finally, try bumping up your memory, although this is very unlikely that this is why your application fails to start.

Resources