Node.js Find out where instance is deployed - javascript

Lately I have been working on a Node.js based program I also wanna make this program avialable to the public however
My code needs to run differently if its for example deployed on heroku or google cloud or AWS
How can I find out on which service my program is deployed in?

Related

Aws server is not running

I have Nodejs code running on aws fargate container.
What I did just add one logic, tested code and pushed code to github. And AWS started pipeline process. When deployment failed I checked cloud watch to know why its failed.
So I found that my Nodejs code requrire one package to run #aws-sdk/middleware-endpoint.
When I tested my nodejs code in my local system I didn't received any such error.
Here is error I received in aws
After reading this error I installed package #aws-sdk/middleware-endpoint and my server is running well.
I am willing to know why #aws-sdk/middleware-endpoint is required suddenly. Although previously my all apis are working fine in same aws server, But today I saw requirement of #aws-sdk/middleware-endpoint.
Anyone can help me what is need of #aws-sdk/middleware-endpoint?

Deploying to an Azure Function connected to a VNet

I've created a v4 Azure Function with JavaScript and Node 16. The storage account used by the Azure Function is connected to a VNet. The Azure Function is also connected to the same VNet. My computer is not connected to the VNet.
I'm able to deploy to the Azure Function using the VSCode Azure Functions extension. However, when I try to deploy using the Azure Function Core Tools (v4.0.4736) via the command line, it fails to upload. Here's my command
func azure functionapp publish MyFunctionApp
If I disable the VNet Route All setting for the Azure Function, then the deployment works.
Is it possible for me to create a deployment script that uses the same approach as the VSCode deployment functionality?

How to run a command in a node app deployed to Heroku?

I'm trying to learn how to deploy my apps and the teacher told us to use Heroku. I have a Node.js app that uses readline library to read a and b and outputs the sum of two numbers to the console and the cycle repeats. Is there a way to pass that data to the app when its deployed to Heroku and running? I found only a heroku-cli command heroku ps:exec but i don't know how to "enter" the running node process from there.
I know this exercise doesn't make sense but for me it's a hard question. Thank You for any help.

Configure Node.js app based on machine type or IDE flags

I want to be able to do different things on my server when running on a web server or running on localhost, like disabling logs or connecting to different data stores.
Is there any way to configure a Node.js app differently based on some IDE definitions (specifically WebStorm in this case) or identify the machine a Node.js express server is running on - and more specifically detecting if the server is running on Azure or on localhost.
The standard way to do this in Node is to use an environment variable that identifies each unique deployment config, combined with custom settings that map to each of those configs:
Here's a good SO topic on that:
environment configs in Node
Combined with the above, in Azure you would define the NODE_ENV variable in Application settings to denote that you're running in Azure, something like this:
In your code you check the value of process.env.NODE_ENV and use the appropriate action based on whether you're in Azure, on localhost, or some other environment as appropriate for your needs.
Here's a small code sample that demonstrates further:
github sample
Good luck!

What is the best practice for figuring out in which AWS Beanstalk Environment my Node.js application is currently running?

My Node.js Express application runs in AWS Beanstalk. I've created three Beanstalk Environments for my application, namely:
DEV (Development)
UAT (User Acceptance Testing)
PROD (Production)
Dependent upon the environment my application is running in I would like to connect to different databases and use different cascading style sheets.
What is the best practice for figuring out in which AWS Beanstalk Environment my Node.js application is currently running?
I get the impression I should be using Beanstalk Environment Tags, but I've not been able to figure out how to access them via my Node.js application.
That's correct, use the environment variables you have configured from the Beanstalk console to let the instance of the application know which environment it is running in. You don't get that many options in a node beanstalk app, but if you say only want to pass a db connection string and a css path, you could do that with PARAM1 and PARAM2, then access these from within your app with
process.env.PARAM1 & process.env.PARAM2
(I've usually pushed these in to more appropriate names/places on application bootstrap).
Your other option is just to pass in some soft of 'env' variable in PARAM1, then have your app work out what to do with your various configurations (but this adds another hidden layer of config into your application).

Categories