Comments (11)
There's an example of this in the README (Environment Variables).
from node-windows.
I am sorry, but I can not find it. Could you please refer to the section where it is described?
from node-windows.
Environment Variables
Sometimes you may want to provide a service with static data, passed in on creation of the service. You can do this by setting environment variables in the service config, as shown below:
var svc = new Service({
name:'Hello World',
description: 'The nodejs.org example web server.',
script: 'C:\\path\\to\\helloworld.js',
env: {
name: "HOME",
value: process.env["USERPROFILE"] // service is now able to access the user who created its' home directory
}
});
You can also supply an array to set multiple environment variables:
var svc = new Service({
name:'Hello World',
description: 'The nodejs.org example web server.',
script: 'C:\\path\\to\\helloworld.js',
env: [{
name: "HOME",
value: process.env["USERPROFILE"] // service is now able to access the user who created its' home directory
},
{
name: "TEMP",
value: path.join(process.env["USERPROFILE"],"/temp") // use a temp directory in user's home directory
}]
});
from node-windows.
Hi again,
I thought this was for setting env-variables for the service itself? Not the application being run by the service? In my application code I get the environment the application was started in by pointing to the process object: process.env.NODE_ENV.
Normally that works on windows with: SET NODE_ENV=production , and then node server.js . On linux/mac you only do: NODE_ENV=production node server.js.
I could not get this to work with setting service env-variables?
Best regards
Christian
On May 16, 2013, at 2:32 PM, Corey Butler <[email protected]mailto:[email protected]>
wrote:
Environment Variables
Sometimes you may want to provide a service with static data, passed in on creation of the service. You can do this by setting environment variables in the service config, as shown below:
var svc = new Service({
name:'Hello World',
description: 'The nodejs.orghttp://nodejs.org example web server.',
script: 'C:\path\to\helloworld.js'smb://path//to//helloworld.js',
env: {
name: "HOME",
value: process.env["USERPROFILE"] // service is now able to access the user who created its' home directory
}
});
You can also supply an array to set multiple environment variables:
var svc = new Service({
name:'Hello World',
description: 'The nodejs.orghttp://nodejs.org example web server.',
script: 'C:\path\to\helloworld.js'smb://path//to//helloworld.js',
env: [{
name: "HOME",
value: process.env["USERPROFILE"] // service is now able to access the user who created its' home directory
},
{
name: "TEMP",
value: path.join(process.env["USERPROFILE"],"/temp") // use a temp directory in user's home directory
}]
});
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-17998135.
from node-windows.
This sets the environment variables for the application, not the daemon/service.
If you want to pass an environment variable like NODE_ENV=production
, it would look something like:
var svc = new Service({
name:'Hello World',
description: 'The nodejs.org example web server.',
script: 'C:\\path\\to\\helloworld.js',
env: [{
name: "NODE_ENV",
value: "production"
}]
});
from node-windows.
Actually, I think I got this confused with a different version I'm working on. The env
variables are passed to the service, but they should still be passed to the application. I'm going to reopen this while I double check.
from node-windows.
OK - I verified that environment variables are indeed passing to the application in this version, not just the service.
I added a a bit of code to the example installer (viewable here). This adds the NODE_ENV=production
to the application. To test, this, you can uncomment line 4 and comment line 5 of helloworld.js. Then run the installer by typing node install
in the examples directory. This will create the service and make a web server available at http://localhost:3000
. When you load this page in the browser, you should see a printout of the process.env
variable where NODE_ENV
is listed.
from node-windows.
Fantastic! Thanks for your help :-)
Sent from my iPhone
On 16. mai 2013, at 15:29, "Corey Butler" <[email protected]mailto:[email protected]> wrote:
OK - I verified that environment variables are indeed passing to the application in this version, not just the service.
I added a a bit of code to the example installer (viewable herehttps://github.com/coreybutler/node-windows/blob/master/example/install.js#L8-L11). This adds the NODE_ENV=production to the application. To test, this, you can uncomment line 4 and comment line 5 of helloworld.jshttps://github.com/coreybutler/node-windows/blob/master/example/helloworld.js#L4-L5. Then run the installer by typing node install in the examples directory. This will create the service and make a web server available at http://localhost:3000. When you load this page in the browser, you should see a printout of the process.env variable where NODE_ENV is listed.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-18000857.
from node-windows.
so there is no way to read directly form the environment variables collection of windows ?
from node-windows.
@eerrecart - You should be able to read any environment variables straight from process.env
, just like any other node.js script.
from node-windows.
This seems to have dropped from the guides, lucky i found this old post! Im now working with a functional NODE_ENV
The guide i followed was here, n
from node-windows.
Related Issues (20)
- Needs windows restart before creating service HOT 1
- 03/30/2023: Please release a non-beta version HOT 2
- node-windows with babel and pkg HOT 1
- Question: Is it possible to split .exe creation and service creation HOT 1
- Comments in the XML file break the service executable
- Unsupported node: v19.0.0 HOT 1
- Event Logging other than event id 1000 HOT 7
- File path HOT 2
- 2023-07-13: React functionality HOT 1
- I need the source code for the binary files under "/bin" HOT 2
- Error while creating daemon folder: daemon already exists HOT 1
- [20231213]: Windows DNS integration HOT 2
- Noticed Typo in the documentation
- logpath property is not working HOT 2
- is it possible to have exe name different than the service name ?
- Why do we need to install it globally?
- March 6 2024 - Does this work with run-p
- Unable to execute child process HOT 1
- Each service is creating 2 seperate node processes HOT 4
- CPU overload due to wrapper launching new Node processes when an unhandled error occurs HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-windows.