# How to Start Appium Sever Pogrammatically With Custom Environments Using NodeJS

**URL:** <https://discuss.appium.io/t/how-to-start-appium-sever-pogrammatically-with-custom-environments-using-nodejs/32122>\
**Category:** Support\
**Created:** [October 16, 2020, 9:06am UTC](https://discuss.appium.io/t/how-to-start-appium-sever-pogrammatically-with-custom-environments-using-nodejs/32122 "2020-10-16T09:06:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![burakaratepe](https://discuss.appium.io/user_avatar/discuss.appium.io/burakaratepe/32/8174_2.png) [@burakaratepe](https://discuss.appium.io/u/burakaratepe)\
**Post date:** [October 16, 2020, 9:06am UTC](https://discuss.appium.io/t/how-to-start-appium-sever-pogrammatically-with-custom-environments-using-nodejs/32122/1 "2020-10-16T09:06:24Z")

</div>

Hi,

I am starting appium server using the code below

```
const appium = require('appium')
server = appium.main(myCapabilities);

```

Appium server starts on “127.0.0.1:{{myCapabilities.port}}/wd/hub”. It’s OK but my appium process using different Environment variables then mine. I can see it when I run command below

```
ps -wwE -p {{processID_of_Appium}}

```

The partitial output of command is

```
PATH=/usr/bin:/bin:/usr/sbin:/sbin

```

When I run command “echo $PATH”, I get output below

```
/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

```

**Conclusion** :  
When I try to start my test on “127.0.0.1:{{myCapabilities.port}}/wd/hub”, I get the error below

> Original error: Unable to launch WebDriverAgent because of xcodebuild failure: not found: carthage.

My carthage is in /usr/local/bin/

How can I start appium server with custom environments using nodejs?

---

<div class="post-metadata">

**Author:** ![mykola-mokhnach](https://discuss.appium.io/user_avatar/discuss.appium.io/mykola-mokhnach/32/4578_2.png) [@mykola-mokhnach](https://discuss.appium.io/u/mykola-mokhnach)\
**Post date:** [October 16, 2020, 11:43am UTC](https://discuss.appium.io/t/how-to-start-appium-sever-pogrammatically-with-custom-environments-using-nodejs/32122/2 "2020-10-16T11:43:26Z")

</div>

Add /usr/local/bin/ to PATH

---

<div class="post-metadata">

**Author:** ![burakaratepe](https://discuss.appium.io/user_avatar/discuss.appium.io/burakaratepe/32/8174_2.png) [@burakaratepe](https://discuss.appium.io/u/burakaratepe)\
**Post date:** [October 16, 2020, 12:42pm UTC](https://discuss.appium.io/t/how-to-start-appium-sever-pogrammatically-with-custom-environments-using-nodejs/32122/3 "2020-10-16T12:42:07Z")

</div>

I’ve already added. This is my output when I run command “echo $PATH”

 ![25](https://discuss.appium.io/uploads/default/original/2X/f/f836699eaab29967ea2901d0a02d90b16734bd3a.png)  
But appium process still see  
“PATH=/usr/bin:/bin:/usr/sbin:/sbin”  
 ![53](https://discuss.appium.io/uploads/default/original/2X/0/09c0b95019d53da0c388a5d25695ad8c7188ff82.png)

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [October 16, 2020, 6:40pm UTC](https://discuss.appium.io/t/how-to-start-appium-sever-pogrammatically-with-custom-environments-using-nodejs/32122/4 "2020-10-16T18:40:10Z")

</div>

Is this running from command line or an IDE? If IDE, which one?

If command line, which shell? Also, how are you adding to your $PATH? For example you might add an 'export $PATH ’ statement to .bash\_profile if you are using bash.

---

<div class="post-metadata">

**Author:** ![burakaratepe](https://discuss.appium.io/user_avatar/discuss.appium.io/burakaratepe/32/8174_2.png) [@burakaratepe](https://discuss.appium.io/u/burakaratepe)\
**Post date:** [October 19, 2020, 4:27am UTC](https://discuss.appium.io/t/how-to-start-appium-sever-pogrammatically-with-custom-environments-using-nodejs/32122/5 "2020-10-19T04:27:00Z")

</div>

I deployed software using electron-packager. So, not from an IDE or terminal.

Additional info: If I run my code using terminal(npm start), appium process see my $PATH as “/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin”.

I am coding on VS Code.

Also, this is inside of my bash\_profile  
 ![11](https://discuss.appium.io/uploads/default/original/2X/e/ec5776fad6f18ecb441c70b451fc166d2b57ae4e.png)

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [October 19, 2020, 4:15pm UTC](https://discuss.appium.io/t/how-to-start-appium-sever-pogrammatically-with-custom-environments-using-nodejs/32122/6 "2020-10-19T16:15:33Z")

</div>

> [@burakaratepe](#):
>
> electron-packager

I did a quick web search on this. According to this page you need to set the variables in .bashrc. You should do an ‘echo $SHELL’ on your command line to make sure you aren’t on ZSH (latest version of os x uses this) in which case you would want to put them in .zshrc.

> **[Electron - Environment Variables](https://www.tutorialspoint.com/electron/electron_environment_variables.htm)**
>
> Electron - Environment Variables - Environment Variables control application configuration and behavior without changing code. Certain Electron behaviors are controlled by environment variables because they are initialized earlier than the command...

This would probably be a useful read for you:

> **[.bashrc vs .bash\_profile](https://linuxize.com/post/bashrc-vs-bash-profile/)**
>
> When invoked, Bash reads and executes commands from from a set of startup files. .bash\_profile is read and executed when Bash is invoked as an interactive login shell, while .bashrc is executed for interactive non-login shell.

---

<div class="post-metadata">

**Author:** ![burakaratepe](https://discuss.appium.io/user_avatar/discuss.appium.io/burakaratepe/32/8174_2.png) [@burakaratepe](https://discuss.appium.io/u/burakaratepe)\
**Post date:** [November 6, 2020, 4:48am UTC](https://discuss.appium.io/t/how-to-start-appium-sever-pogrammatically-with-custom-environments-using-nodejs/32122/7 "2020-11-06T04:48:24Z")

</div>

It did not work. But I found a solution.

I am adding this code block before appReady() state.

`process.env.PATH = process.env.PATH.includes(actualPath) ? process.env.PATH : actualPath + process.env.PATH;`

Then everything works fine.

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [November 6, 2020, 5:30pm UTC](https://discuss.appium.io/t/how-to-start-appium-sever-pogrammatically-with-custom-environments-using-nodejs/32122/8 "2020-11-06T17:30:11Z")

</div>

Thanks for posting your solution.
