Click here to Skip to main content
15,889,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I installed node.js and npm in my project.
To start npm, I need to run bat file manually. I don't want to run bat file in c# code too because of server security.

What I have tried:

This is my bat file.

@ECHO off
set MYINFO_APP_CLIENT_ID=MyInfo_SelfTest
set MYINFO_APP_CLIENT_SECRET=password
set MYINFO_APP_REDIRECT_URL=http://localhost:3001/callback
set MYINFO_APP_REALM=http://localhost:3001

npm start
Posted
Updated 14-Jan-18 23:23pm
v2

1 solution

You can achieve the same result in C#. For that, you need to set the four environment variables and then launch the process.
Environment.SetEnvironmentVariable Method (String, String)[^]
Process.Start Method (String, String)[^]
Something like:
C#
Environment.SetEnvironmentVariable("MYINFO_APP_CLIENT_ID", "MyInfo_SelfTest");
Environment.SetEnvironmentVariable("MYINFO_APP_CLIENT_SECRET", "password");
Environment.SetEnvironmentVariable("MYINFO_APP_REDIRECT_URL", "http://localhost:3001/callback");
Environment.SetEnvironmentVariable("MYINFO_APP_REALM", "http://localhost:3001");
Process.Start("npm", "start");

You may have to specify the full path to the npm executable.
Kindly.
 
Share this answer
 
Comments
helenmoon 15-Jan-18 21:54pm    
I am actually trying to use npm start without using command prompt. Is there any to use npm?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900