Refer environment variable in Run.json for Fleet IDE - jetbrains-ide

I am working on setting up the JetBrains Fleet for JavaScript development.
Here is my hard coded run.json look like.
"configurations": [
{
"type": "command",
"name": "local test",
"program": "npm",
"args": [
"run",
"test",
"ssoni_local"
],
}
]
Instead of using ssoni (my username), I would like to use ${USERNAME} environment variable so the same run.json file can be used my other team members as well.
How can I achieve the same?
Also same needs for the hostname variable as well. Instead of hardcoding machine name want to use an environment variable.

Related

VS Code-debugger, How to use node with command line option in launch.json for starting a script

The script that is meant must be executed with the command
node --no-experimental-fetch server.js
otherwise a error occurs.
To use the VS Code-debugger and not to start the script always with the shell,
I want to integrate the command in the launch.json.
I generated and edited the following launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Start server",
"skipFiles": [
"<node_internals>/**"
],
"args": [
"--no-experimental-fetch"
],
"program": "${workspaceFolder}/server.js"
}
]
}
but the error occurs.
Has someone an idea what should be edit in the launch.json that fixes the issue?
Thanks for reading and answering this question, I appreciate it.
Instead of "args" you should use "runtimeArgs" with arguments for node(.exe).
You might as well use environment variable definition for "NODE_OPTIONS":
...
env: {
"NODE_OPTIONS": "--no-experimental-fetch"
},
...

VS Code Extension - How to set NODE_EXTRA_CA_CERTS?

I am creating an extension for VS Code. In that, before connecting to database, I need to set the env variable NODE_EXTRA_CA_CERTS to path to certificate file. Normally, If I am running any javascript code(myFile.js) that connects to my database, I run following command in terminal -
export NODE_EXTRA_CA_CERTS='path-to-certificate-file'
node myFile.js
Now, my extension has code that connects to my database, but how do i set the env variable NODE_EXTRA_CA_CERTS before running the extension ?
I tried following ways but it didn't work -
Used process.env.NODE_EXTRA_CA_CERTS='path-to-certificate-file' inside extension code.
Set this env variable in launch.json
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}",
"osx": {
"env": {"NODE_EXTRA_CA_CERTS":"path-to-certificate-file"}
}
}
I added this line in my .zshrc file
export NODE_EXTRA_CA_CERTS='path-to-certificate-file' .
How env variables are set for VS Code Extension? Is there any reason or am i doing anything wrong which is why it isn't working ?

Set env var for Node JS when launching through VS Code

I have Node JS Azure function that when I run locally needs the NODE_TLS_REJECT_UNAUTHORIZED=0 environment variable needs setting for my code to work. This is because I am connecting to an emulated Cosmos DB running locally on my machine which require Node to allow for self signed certificates.
I only want this environment variable setting when I run locally as in production I will be using a real (i.e. non emulated) Cosmos DB instance. Rather than putting and #if debug in my code (or the equivalent for a Node Azure Function) I'd like my VS Code project to set the env var when it is launched.
I've trying following this answers advice but when VS Code launches the program the environment variable is not set as I get a runtime error in my code about self signed certificates not being authorised. My launch.json looks like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Node Functions",
"type": "node",
"request": "attach",
"port": 9229,
"preLaunchTask": "func: ",
},
],
"environment": [{
"name": "NODE_TLS_REJECT_UNAUTHORIZED",
"value": "0"
}],
}
If I set the env var directly in code using process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0 everything is fine. I don't know how I can get VS Code to set this, or if it is even possible.
Please update
"environment": [{
"name": "NODE_TLS_REJECT_UNAUTHORIZED",
"value": "0"
}],
To Be
"env": {
"name": "NODE_TLS_REJECT_UNAUTHORIZED",
"value": "0"
},
Also please check the alternatives.
You can Update package.json scripts to add all environment variables on start like "runLocal": "NODE_TLS_REJECT_UNAUTHORIZED=0 ... your start code " or You can use third party lib called dotenv
this is how it works
01- Create .env file
02- Write all your environment variables key=val NODE_TLS_REJECT_UNAUTHORIZED=0
03- Update package.json scripts to add "runLocal": "NODE_ENV=dev ... your start code "
04- Check if node NODE_ENV is equal dev then load the dotenv
05- Import module in case of node env is local and call config function require('dotenv').config()

Hosting environment why is it set to Production, Difference between host.json and local.settings.json

I have two questions on .net core applications for functions. I am using blobtrigger.
1) When I run my project locally I get this 'Hosting environment' on the command prompt console, I want to understand where is this variable set and how can I change it to development. Its misleading since I am only developing locally.
[5/23/2019 7:00:20 PM] Host started (773ms)
[5/23/2019 7:00:20 PM] Job host started
Hosting environment: Production
Content root path: C:Myproject\bin\Debug\netcoreapp2.1
Now listening on: http://0.0.0.0:7071
2) What is the difference between host.json and local.settings.json. When can host.json be used? So far I have only used local.settings.json and when I publish to azure I am creating configurations mentioned in local.settings.json but Host.json is not used it looks like. Whats the purpose of host.json file is.
"Hosting environment" on the console comes from the environment variable ASPNETCORE_ENVIRONMENT. When this variable is not set, it defaults to "Production".
It's set here: HostingEnvironment.cs
The reason behind this default is described in this github issue.
This variable is popular in dotnet core web apps, but it is not mentioned in official docs in Azure functions (I am not sure why). If you write a for loop and output all the environment variables to console from within a function, you will find that this variable is not set by default - neither in production, nor when running in Visual Studio.
If you wish to define this variable locally, you have a few different ways.
Setting the environment variable via command line:
setx ASPNETCORE_ENVIRONMENT "Development"
Defining this in Properties\launchSettings.json:
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Defining this in local.settings.json:
"Values": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Note that this variable is not automatically defined to production when you publish your app to azure. You will have to define this variable in "Configuration" -> "Application Settings" in Azure portal.
In azure functions there appears to be another similar environment variable called AZURE_FUNCTIONS_ENVIRONMENT. This one is defined by default locally.
AZURE_FUNCTIONS_ENVIRONMENT = Development
This is not defined in production by default, and can be defined in the azure portal.
Difference between host.json and local.settings.json:
host.json is to configure pre-defined settings that function app infrastructure understands. It applies to both local and production environments. It doesn't allow custom settings though. local.settings.json on the other hand is useful for defining custom settings. host.json is committed into source control, but local.settings.json is usually left out of source control, and is considered to be a good location to store secrets and connection strings for development.
More details here about the differences: https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-vs#create-an-azure-functions-project (scroll to the end of that section)
host.json reference
local.settings.json reference
You can add "ASPNETCORE_ENVIRONMENT": "Development" in the local.settings.json, to change the hosting environment:
As you know, local.settings.json is just for local testing and will not be published to azure portal. For host.json(which will be published to azure), you can configure settings like loglevel(if you want to log) in azure portal. More details, please refer to this article of host.json.
Sometimes, most times, Microsoft has strange ways of doing things... we as the community have to either find a way around them, or conform. Well, if you are one of those who cant survive the idea to conforming to something that doesn't make sense, here is a solution:
Delete local.settings.json
Create two files (or many, each for your environment), and name them {environment}.local.settings.json eg: development.local.settings.json and production.local.settings.json
Create a task to copy your current environment file to local.settings.json
Here we go again: we got to duplicate tasks...
[
{
"label": "use development.local.settings.json",
"command": "cp development.local.settings.json local.settings.json",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/..."
}
},
{
"label": "use production.local.settings.json",
"command": "cp production.local.settings.json local.settings.json",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/..."
}
},
{
"label": "azure-func-development",
"type": "func",
"dependsOn": [
"use development.local.settings.json",
"build"
],
"dependsOrder": "sequence",
"options": {
"cwd": "${workspaceFolder}/.../bin/Debug/netcoreapp2.2"
},
"command": "host start",
"isBackground": true,
"problemMatcher": "$func-watch"
},
{
"label": "azure-func-production",
"type": "func",
"dependsOn": [
"use production.local.settings.json",
"build"
],
"dependsOrder": "sequence",
"options": {
"cwd": "${workspaceFolder}/.../bin/Debug/netcoreapp2.2"
},
"command": "host start",
"isBackground": true,
"problemMatcher": "$func-watch"
}
]
Don't get tired, we are not finished duplicating, yet...
Lets duplicate the launch.json configurations:
[
{
"name": "[Development] Attach to Azure .NET Functions",
"type": "coreclr",
"request": "attach",
"preLaunchTask": "azure-func-development",
"processId": "${command:azureFunctions.pickProcess}"
},
{
"name": "[Production] Attach to Azure .NET Functions",
"type": "coreclr",
"request": "attach",
"preLaunchTask": "azure-func-production",
"processId": "${command:azureFunctions.pickProcess}"
}
]

the --harmony flag in the args parameter seems not to work

the --harmony flag for node in the args parameter seems not to work. I can't use fat array functions.
Here part of lounch.json
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch app.js",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "./app.js",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": ["--harmony"],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Environment variables passed to the program.
"env": { }
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858
}
]
Is there a way to fix the problem myself?
The "args" parameter is not for the node process, but rather arguments for the app.
I was confused by this myself, the documentation should make this clearer.
See this question for a workaround: How to start nodejs with custom params from vscode

Resources