Reading environment variables with Javascript

前端 未结 6 866
灰色年华
灰色年华 2020-12-10 10:37

I need to read the system time from the environment variables on the client\'s OS. I searched on Stackoverflow and found that this isn\'t possible. However, those answers we

6条回答
  •  甜味超标
    2020-12-10 10:45

    All of the answers are today (at the time of writing) long outdated. :)

    Of course, JS is still sandboxed, but that does not prevent anyone from using something like environment variables in client software. What you need to know and use wisely is the transfer of data of any kind from the operating system into a front-end application.

    Several front-end frameworks may help here. E.g. an Angular application created with @angular/cli provides use cases for different environments out of the box. In an application configuration file (e.g. angular.json) you can configure the options, variables, values, whatever you need that you transport into your front end application via e.g. webpack. They may only be read once and can not change at runtime.

    Following library nwjs.io tries something new: it lets you call all Node.js modules directly from DOM.

    In docked/docker environments, there are other expectations for backend and frontend software, and these environments are configured differently and properly constrained from the OS's point of view.

提交回复
热议问题