Giter VIP home page Giter VIP logo

Comments (11)

coreybutler avatar coreybutler commented on May 26, 2024

There's an example of this in the README (Environment Variables).

from node-windows.

christianalfoni avatar christianalfoni commented on May 26, 2024

I am sorry, but I can not find it. Could you please refer to the section where it is described?

from node-windows.

coreybutler avatar coreybutler commented on May 26, 2024

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.

christianalfoni avatar christianalfoni commented on May 26, 2024

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.

coreybutler avatar coreybutler commented on May 26, 2024

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.

coreybutler avatar coreybutler commented on May 26, 2024

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.

coreybutler avatar coreybutler commented on May 26, 2024

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.

christianalfoni avatar christianalfoni commented on May 26, 2024

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.

eerrecart avatar eerrecart commented on May 26, 2024

so there is no way to read directly form the environment variables collection of windows ?

from node-windows.

coreybutler avatar coreybutler commented on May 26, 2024

@eerrecart - You should be able to read any environment variables straight from process.env, just like any other node.js script.

from node-windows.

FoldZero avatar FoldZero commented on May 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.