PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] How to set multiple environment variables in a single line on Windows?

 August 21, 2022     environment-variables, jestjs, node.js     No comments   

Issue

I'm working on a Node.js project and using Jest as the test framework. This project runs on Windows as it happens, and I'm having a heck of a time setting more than one environment variable on the command line.

Here's the relevant line in package.json

  "scripts": {
     "test": "SET NODE_ENV=test & SET DB_URI=postgresql://<database stuff>> & jest -t Suite1 --watch --verbose false"
  },

As can be seen above, I'm setting both a NODE_ENV and DB_URI environment variable prior to running jest via npm run test.

My problem is the that DB_URI environment variable doesn't appear to be set when jest runs. The error I get back from jest makes it obvious it can't find it. I do know that the first, NODE_ENV environment variable is set ok, but am not sure what's wrong with the second one, did I get the syntax wrong somehow? Is anyone with jest experience on Windows doing something similar to what I'm trying?


Solution

Just make the following change:

Use &&, also you need to remove the white space before and after the "&&".

"scripts": {
     "test": "SET NODE_ENV=test&&SET DB_URI=postgresql://<database stuff>>&&jest -t Suite1 --watch --verbose false"
  },


Answered By - Prabhjot Singh Kainth
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing