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

Monday, August 22, 2022

[FIXED] How to resolve a path that includes an environment variable, in nodejs?

 August 22, 2022     environment-variables, javascript, node.js     No comments   

Issue

I would like to run an executable and its path contains an enviroment variable, for example if I would like to run chrome.exe I would like to write something like this

var spawn = require('child_process').spawn;
spawn('chrome',[], {cwd: '%LOCALAPPDATA%\\Google\\Chrome\\Application', env: process.env})

instead of

var spawn = require('child_process').spawn;
spawn('chrome',[], {cwd: 'C:\\Users\myuser\\AppData\\Local\\Google\\Chrome\\Application', env: process.env}).

Is there a package I can use in order to achieve this?


Solution

These answers are crazy. Just can use path:

const folder = require('path').join(
    process.env.LOCALAPPDATA,
    'Google/Chrome/Application',
);

console.log(folder); // C:\Users\MyName\AppData\Local\Google\Chrome\Application


Answered By - ZYinMD
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • 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