Run the MEAN stack with IaaS

I succeeded in running this MEAN stack on Heroku, so then I tried it on IaaS (AWS).

Installing http-server referring to ※p271, then building the product with
$ng build --prod
It didn't work well, and I tried using this as a reference, but no good.

Finally, after deleting node_module and package-lock.json, when I run npm install, the error disappears. Before that, I didn't do npm install, so I think it might be this reason.
After that, I did ng build --prod, accessed the AWS current directory, released the port, moved to the dist folder, and executed http-server.
(It will not work if you add the project directory to the URL, so be careful. Also it is necessary to add the port number at the end of the URL)
It seems to work with $npm start, but it didn't not go well.
※: Angular web application development start book

------- -8/26 P.S. -------
Although the entry screen appears above, the data stored in the DB is not read.
An error also occurs in node server.js, so re-create the project reffering to "https://devcenter.heroku.com/articles/mean-apps-restful-api" and execute
$ng build --prod
Then in server.js, change
process.env.MONGODB_URI
to
"mongodb: // xxx".
then
$npm start (or node server.js)
I was able to do it well.

Furthermore, referring to this article , save the .env file in the project folder, install dotenv from npm locally with --save option, change server.js partially and read dotenv.
And the data could be read without embedding mongodb URL in the program directly.
->There seems to be a way to write in process.env file , but stop this because you want to set it locally.

However, if you upgrade to heroku with this code, it does not work well maybe due to dotenv. So when using heroku, it seems better to set the environment variable straightly.

Comments

Popular posts from this blog

Pops

Earthquake happend in Japan

Goldsmith College, UK

Iga ueno city, Ninja museum

Our new family !