`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-L133 Replies
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.
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'
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