I'm using ExpressJS to connect the dots between NodeJS and my Angular app. I wanted to install this npm package norobot: to leverage the process object.
I'd like to know where/how to set the NODE_ENV in an App Service within Microsoft Azure.
I was pointed here,
https://learn.microsoft.com/en-us/azure/app-service/web-sites-configure#howtochangeconfig
But the current-day Azure portal looks significantly different versus what the documentation has supplied, leading me to a big disconnect.
If you could point me in the right direction, that'd be appreciated.
Additional FYI,
At run-time, my stack is running on Node.js 9.4.
I wanted to install this npm package norobot: to leverage the process object.
norobot package has absolutely nothing to do with process.
But the current-day Azure portal looks significantly different versus what the documentation has supplied, leading me to a big disconnect.
Looks really shouldn't matter (to an extent), they serve as a visual guide.
The key section of the guide/docs you posted is App Settings:
This section contains name/value pairs that your web app will load on start up.
PHP, Python, Java and Node applications can access these settings as environment variables at runtime. For each app setting, two environment variables are created; one with the name specified by the app setting entry, and another with a prefix of APPSETTING_. Both contain the same value.
So following a similar answer: https://stackoverflow.com/a/34622196/2382650
set: NODE_ENV: some_value as shown above and it will be availble in your Express app as process.env.NODE_ENV
Related
I have a node.js application deployed on Azure as "myClient" App Service, and several configuration files which contain values specific to their runtime environment:
appconfig.json for debugging on localhost (not applicable to Azure).
appconfig.production.json for running in the App Service production Slot "myClient".
appconfig.development.json for running in the App Service development Slot "myClient/development".
myClient app contains an "environment.prod.ts" file:
export const environment = {
production: true,
hmr: false,
appConfig: 'appconfig.development.json'
};
The app is published with "npm run publish" from DOS shell.
I can upload the package to "myClient/development" Slot and it runs fine with no issues.
When I want to create a package for the "myClient" Production Slot I make the following change to "environment.prod.ts" file and publish again.
appConfig: 'appconfig.production.json'
The published package is uploaded to Azure Production Slot and it runs fine with no issues.
HERE IS THE PROBLEM with this approach:
source code must be modified to specify the environment.
publishing takes 25-30 minutes.
cannot use Swap Slot feature in Azure.
If I could access an Application Setting (analogous to ASPNETCORE_ENVIRONMENT), I could then select the correct configuration file (in code) based on the environment for that Slot, and then use Swap to deploy from development to production.
I have searched the Internet (including this site) to see if there is a way to access App Service Application Settings from a node application, and have not found any article describing how to accomplish this.
Is it possible to reference Azure Configuration Application setting from a node application using javascript?
Is there alternative process to modifying the source code and publishing for each environment?
There is a WEBSITE_SLOT_NAME app setting that App Service injects and whose value is the name of the current running slot. You could just leverage this to decide which config to use.
You could also just use a custom app setting that is slot-specific (sticks to the slot) and hardcode the value for each slot as required.
This is a follow on to my original question
I am trying to set up IBM's Informix driver for use with NodeJS on MacOS.
After viewing the Readme file for the Informix NPM library, I am a little confused as to what the environment variables are and whether I need to apply them all?
I managed to track down the install location for the SDK files: Applications/IBM/informix and then added this to the ~/.bash_profile file as so:
export INFORMIXDIR=/Applications/IBM/informix
export PATH=$PATH:$INFORMIDIR
Should I change my PATH to include /bin at the end?
I am also confused by the remainder of the statements in the Readme.
I was expecting to set the server name and host dynamically rather than hard-coding them?
Some guidance would be appreciated.
The PATH env variable needs $INFORMIXDIR/bin. (There is nothing in plain $INFORMIXDIR worth running other than the install script).
INFORMIXSERVER and INFORMIXSQLHOSTS may be needed for testing the module, but they are not hardcoded (the module will not store that anywhere)
You will always be able to specify a different INFORMIXSERVER/INFORMIXSQLHOSTS at runtime.
I never tried it on a MacOS, but you may also need to add DYLD_LIBRARY_PATH, something like "export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH" to your script.
Some MacOS binaries will use DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH.
Following my previous question, I have followed webpack guidelines of using multiple targets to build my NPM package. https://webpack.js.org/concepts/targets/#multiple-targets
I now have two different output files, index.js which is the browser bundle and index.node.js which is obviously supposed to run on the backend.
The app should run on both browser and Node, the code is mostly reused but there is some big difference around accessing files etc. which means I do need two separate files depending on what platform should the app run.
My question is how should I publish this library in a way that user can consume it like import {//SOME OBJECT} from 'my-published-library' when they import it from NPM regardless if they are using it on the browser or in their node application? If I try that at the moment it always defaults to index.js which works in the browser but not in Node.
Not sure if this is what you're looking for but if you are installing for the browser, the package.json provides a field to set the entry point.
https://docs.npmjs.com/files/package.json#browser
I am developing an application which comprises a SPA front end and a Rest back-end.
To implement the Rest back-end I am using Node and Express.
Considering that both front-end and back-end are written in JavaScript (and TypeScript), I would like to share some code between these 2 parts (namely Interfaces and simple utils).
So basically my project is composed of three parts: Client, Server, Shared. Therefore I am inclined to have a project directory structure similar to this:
ProjecFolder
ClientFolder
.....
ServerFolder
.....
SharedFolder
.....
I am looking for suggestions on how best organize my project. I have done some research and I have found this interesting article which suggests to use a mechanism based on Gulp tasks that copy all files from SharedFolder into both ClientFolder and ServerFolder and then runs transpling.
I am wondering whether there can be an alternative approach or tools that perform what otherwise has to be configures as Gulp workflow.
My recommendation is to use a package manager tool. When you have dependencies, and the requirements of the server changed, you have to change the module. You don't want the SPA (frontend), to break, when you need to make changes to the server.
This is why package managers give you versions. Each module that depends on your shared code, can use a different version of it. You can use NPM for that. Build a module, publish it, and install it on your frontend and backend.
Many times, in production you split the frontend and backend. The frontend may exist in a file storage system (S3, Google Cloud Storage and similar), and the backend executed on your servers. Then it will be harder to use the same files on both systems.
I want to set up a second node.js server to run an express.js application which is an exact and independent copy of my current html (client-side) and js (server-side) files.
The reason is that I want to deploy my current code in a production environment that can be used by the team that will not be shut down, while I work on my current code in a development environment.
My worry is that I have added my current node.js server to my path and I am not sure if upon installation of the second node.js server my command to start the second server will interfere with the node.js server I have saved in my path variable.
Here are a couple of things to know before I ask my questions:
I am working on a machine with a Linux distribution.
I am using Express.js routing
I am using the instructions to install another instance of node.js and express.js at:
www.vultr.com/docs/installing-node-js-and-express
My questions are as follows:
Is this as simple as installing node and express as per the instructions in the link above into a new directory and running from the new path without storing it in my path variable?
Is there a better and more effective way to create a production and a development environment so that my team can use the app I have built without interfering with my current instance of node while ensuring 100% up time for the app deployed in production?
Once the 2nd server is instantiated, how do I make the call from my terminal so that it does not turn on/off the original node server I have running from my path variable?
Considering that the link above is a how to on how to install node and express from scratch and in Ubuntu (I am on CentOS - Gnome), is there a better "how to" that I should use to complete the second node and express install?
When creating the new Port for the second node/express server to listen on can I just pick any number with 4 digits or is there a particular set of numbers that would be more effective to use? I am already using Port:3000 for my first instance in my development environment.
Thank you for your guidance.
Developing and serving from the same PC is not preferable, however, if you must, this is what you can do.
First, there is no need to install a second copy of node on to your machine - you can run multiple processes of node on the same machine without any problem.
What I suggest you do is this:
If you haven't already, commit your project into a git repository
Create separate branches for development and production, as shown here: http://nvie.com/posts/a-successful-git-branching-model/#the-main-branches
Every time you are ready to publish a new piece of code, push it to the master branch
Move all configuration parameters to a config file, and create s separate one for dev/production, you can do this easily with the config package: https://www.npmjs.com/package/config
Clone your repo to a separate folder which would always remain on the master (production) branch
Run you server from that folder - your team could then connect to it
All development would be done in the original folder. Once you are ready, push to master, and pull on the production folder.
Regarding the port numbers, you can use anything that is above 1024 and below 65535