1

What is the equivalent statement in Dart for the Node Express code:

app.settings.env

as in

console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);

I've looked at ArgResults but I'm not clear as to how to use it.

basheps
  • 10,034
  • 11
  • 36
  • 45

1 Answers1

3

From the express documentation:

env - Environment mode, defaults to process.env.NODE_ENV or "development"

The problem boils down to accessing environment variables, which has been addressed here: Access to user environment variable

import 'dart:io';

main() {
    String env;
    if (Platform.environment.containsKey("DART_ENV")) {
        env = Platform.environment["DART_ENV"];
    } else {
        env = "development";
    }
}

ArgResults just parses command-line arguments, which is likely not what you want. Use ArgParser instead.

Community
  • 1
  • 1
beatgammit
  • 19,817
  • 19
  • 86
  • 129