Node uygulamanızın test mi production mı, development mu olduğunu ve ona göre çalıştırılmasına karar verdiğiniz noktada sizin de benim gibi
process.env.NODE_ENV
değerine atama yapmanız gerekecek. Ama önce process.env ne getiriyor ve anlamı ne?
C:\temp\nodeapp>node app.js process.env = {"ALLUSERSPROFILE":"C:\\ProgramData","APPDATA":"C:\\Users\\cem\\AppData\\Roaming","CommonProgramFiles":"C:\\Program Files\\Common Files","CommonProgramFiles(x86)":"C:\\Program Files (x86)\\Common Files","CommonProgramW6432":"C:\\Program Files\\Common Files","COMPUTERNAME":"G6YE305003NG","ComSpec":"C:\\Windows\\system32\\cmd.exe","ConEmuANSI":"ON","ConEmuAnsiLog":"","ConEmuArgs":"","ConEmuBackHWND":"0x000A098A","ConEmuBaseDir":"C:\\_Portables\\ConEmu\\ConEmu","ConEmuBuild":"141208","ConEmuConfig":"","ConEmuDir":"C:\\_Portables\\ConEmu","ConEmuDrawHWND":"0x00040A1E","ConEmuDrive":"C:","ConEmuHooks":"Enabled","ConEmuHWND":"0x00080978","ConEmuPID":"4228","ConEmuServerPID":"4600","ConEmuWorkDir":"C:\\Users\\cem","ConEmuWorkDrive":"C:","FP_NO_HOST_CHECK":"NO","HOMEDRIVE":"C:","HOMEPATH":"\\Users\\cem","LOCALAPPDATA":"C:\\Users\\cem\\AppData\\Local","LOGONSERVER":"\\\\G6YE305003NG","NUMBER_OF_PROCESSORS":"4","OS":"Windows_NT","Path":"C:\\_Portables\\ConEmu\\ConEmu;C:\\Program Files\\Common Files\\Microsoft Shared\\Windows Live;C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\Windows Live;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\3.0\\bin\\x86;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\3.0\\bin\\x64;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\;C:\\Program Files\\Microsoft\\Web Platform Installer\\;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;c:\\_Portables\\mysql-5.6.15-winx64\\bin;C:\\Program Files (x86)\\MySQL\\MySQL Utilities 1.3.6\\;C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin;C:\\Program Files\\TortoiseSVN\\bin;C:\\Program Files (x86)\\Microsoft SDKs\\TypeScript\\1.0\\;C:\\xampp\\php;C:\\ProgramData\\ComposerSetup\\bin;C:\\Program Files (x86)\\Windows Live\\Shared;C:\\Program Files (x86)\\Git\\cmd;C:\\_Portables\\ConEmu;C:\\Program Files\\nodejs\\;C:\\Users\\cem\\AppData\\Roaming\\npm","PATHEXT":".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC","PROCESSOR_ARCHITECTURE":"AMD64","PROCESSOR_IDENTIFIER":"Intel64 Family 6 Model 58 Stepping 9, GenuineIntel","PROCESSOR_LEVEL":"6","PROCESSOR_REVISION":"3a09","ProgramData":"C:\\ProgramData","ProgramFiles":"C:\\Program Files","ProgramFiles(x86)":"C:\\Program Files (x86)","ProgramW6432":"C:\\Program Files","PROMPT":"$P$G","PSModulePath":"C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\","PUBLIC":"C:\\Users\\Public","SESSIONNAME":"Console","SystemDrive":"C:","SystemRoot":"C:\\Windows","TEMP":"C:\\Users\\cem\\AppData\\Local\\Temp","TMP":"C:\\Users\\cem\\AppData\\Local\\Temp","USERDOMAIN":"G6YE305003NG","USERNAME":"cem","USERPROFILE":"C:\\Users\\cem","VS110COMNTOOLS":"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\Tools\\","VS120COMNTOOLS":"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\Tools\\","windir":"C:\\Windows","windows_tracing_flags":"3","windows_tracing_logfile":"C:\\BVTBin\\Tests\\installpackage\\csilogfile.log"}
Hangi işletim sistemini kullanırsanız kullanın, sistem üzerinde kaynaklara erişim için ortam değişkenleri kullanılır. Bu değişkenler hem kullnıcıya hem sisteme göre iki türde olur. Sisteme dahil olan değikenlere tüm kullanıcılar ve uygulamaları erişebilirken kullanıcıya ait olanlara ise sadece değişkeni kendisinde tanımlı kullanıcı erişebilir.
Sistem değişkenleri registry içinde burada tanımlıdır: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\
Yerel değişkenler(kullanıcı değişkenleri) ise burada: HKEY_CURRENT_USER\Environment\
Ayrıca bu değişkenlere bilgisayarım ikonuna sağ tuş ve sistem değişkenleri kısmından erişebilirsiniz:
Tüm ortam değişkenlerini bulmamızı sağlayan node scriptini bir dosyaya yazın ve
c:\>node dosyaAdi.js
diyerek çalıştırın:console.log('process.env = ' + JSON.stringify(process.env));
Sonucu json formattırladığımızda değerleri açık seçik göreceksiniz:
{ "ALLUSERSPROFILE": "C:\\ProgramData", "APPDATA": "C:\\Users\\cem\\AppData\\Roaming", "CommonProgramFiles": "C:\\Program Files\\Common Files", "CommonProgramFiles(x86)": "C:\\Program Files (x86)\\Common Files", "CommonProgramW6432": "C:\\Program Files\\Common Files", "COMPUTERNAME": "G6YE305003NG", "ComSpec": "C:\\Windows\\system32\\cmd.exe", "ConEmuANSI": "ON", "ConEmuAnsiLog": "", "ConEmuArgs": "", "ConEmuBackHWND": "0x000A098A", "ConEmuBaseDir": "C:\\_Portables\\ConEmu\\ConEmu", "ConEmuBuild": "141208", "ConEmuConfig": "", "ConEmuDir": "C:\\_Portables\\ConEmu", "ConEmuDrawHWND": "0x00040A1E", "ConEmuDrive": "C:", "ConEmuHooks": "Enabled", "ConEmuHWND": "0x00080978", "ConEmuPID": "4228", "ConEmuServerPID": "4600", "ConEmuWorkDir": "C:\\Users\\cem", "ConEmuWorkDrive": "C:", "FP_NO_HOST_CHECK": "NO", "HOMEDRIVE": "C:", "HOMEPATH": "\\Users\\cem", "LOCALAPPDATA": "C:\\Users\\cem\\AppData\\Local", "LOGONSERVER": "\\\\G6YE305003NG", "NUMBER_OF_PROCESSORS": "4", "OS": "Windows_NT", "Path": "C:\\_Portables\\ConEmu\\ConEmu;C:\\Program Files\\Common Files\\Microsoft Shared\\Windows Live;C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\Windows Live;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\3.0\\bin\\x86;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\3.0\\bin\\x64;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\;C:\\Program Files\\Microsoft\\Web Platform Installer\\;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;c:\\_Portables\\mysql-5.6.15-winx64\\bin;C:\\Program Files (x86)\\MySQL\\MySQL Utilities 1.3.6\\;C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin;C:\\Program Files\\TortoiseSVN\\bin;C:\\Program Files (x86)\\Microsoft SDKs\\TypeScript\\1.0\\;C:\\xampp\\php;C:\\ProgramData\\ComposerSetup\\bin;C:\\Program Files (x86)\\Windows Live\\Shared;C:\\Program Files (x86)\\Git\\cmd;C:\\_Portables\\ConEmu;C:\\Program Files\\nodejs\\;C:\\Users\\cem\\AppData\\Roaming\\npm", "PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC", "PROCESSOR_ARCHITECTURE": "AMD64", "PROCESSOR_IDENTIFIER": "Intel64 Family 6 Model 58 Stepping 9, GenuineIntel", "PROCESSOR_LEVEL": "6", "PROCESSOR_REVISION": "3a09", "ProgramData": "C:\\ProgramData", "ProgramFiles": "C:\\Program Files", "ProgramFiles(x86)": "C:\\Program Files (x86)", "ProgramW6432": "C:\\Program Files", "PROMPT": "$P$G", "PSModulePath": "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\", "PUBLIC": "C:\\Users\\Public", "SESSIONNAME": "Console", "SystemDrive": "C:", "SystemRoot": "C:\\Windows", "TEMP": "C:\\Users\\cem\\AppData\\Local\\Temp", "TMP": "C:\\Users\\cem\\AppData\\Local\\Temp", "USERDOMAIN": "G6YE305003NG", "USERNAME": "cem", "USERPROFILE": "C:\\Users\\cem", "VS110COMNTOOLS": "C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\Tools\\", "VS120COMNTOOLS": "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\Tools\\", "windir": "C:\\Windows", "windows_tracing_flags": "3", "windows_tracing_logfile": "C:\\BVTBin\\Tests\\installpackage\\csilogfile.log" }
Bu environment variables uzun klasör adları yazmayı önlediği gibi hızlıca çalıştırmak istediğiniz uygulamalara da klasör adları eklemeden gidebilmenizi sağlar. Klasörlere ise %YOL_ADI% ile erişebilirsiniz.
Referanslar: