N
Nuxt2y ago
basic-ph

`process.server` and `process.client`

Hello everyone! Disclaimer: Maybe this is a trivial question but I have not been able to find an answer in the documentation or elsewhere on the web. I was wondering where the process.server and process.client syntax used in this example came from: https://github.com/nuxt/nuxt/blob/main/examples/other/locale/composables/locale.ts#L7-L13
3 Replies
manniL
manniL2y ago
It is nuxt-based and can be used to execute code only on client/server side. Strange that it isn't part of the current docs but you can check it e.g. @ https://nuxtjs.org/docs/concepts/server-side-rendering#window-or-document-undefined
Nuxt
Server Side Rendering
Server-side rendering (SSR), is the ability of an application to contribute by displaying the web-page on the server instead of rendering it in the browser.
Fabian B.
Fabian B.2y ago
The interesting thing is that in some cases, "process" is not defined, and so a check for process.client will throw. This is when you nuxt generate. At least that was my experience today, had to switch to typeof window !== 'undefined'
basic-ph
basic-phOP2y ago
Thank you guys! I saw that Nuxt 2 documentation page but the fact that process.client and process.server are nuxt-based was not very clear to me
Want results from more Discord servers?
Add your server