2022-10-06 09:15:30 +00:00
---
title: "How Nuxt Works?"
description: "Nuxt is a minimal but highly customizable framework to build web applications."
---
2022-04-06 05:56:08 +00:00
# How Nuxt Works?
2022-01-27 17:02:42 +00:00
Nuxt is a minimal but highly customizable framework to build web applications. This guide helps you better understand Nuxt internals to develop new solutions and module integrations on top of Nuxt.
2022-08-13 07:27:04 +00:00
## The Nuxt Interface
2022-01-27 17:02:42 +00:00
2022-08-13 07:27:04 +00:00
When you start Nuxt in development mode with `nuxi dev` or building a production application with `nuxi build` ,
2022-01-27 17:02:42 +00:00
a common context will be created, referred to as `nuxt` internally. It holds normalized options merged with `nuxt.config` file,
2022-11-16 10:04:28 +00:00
some internal state, and a powerful [hooking system ](/docs/api/advanced/hooks ) powered by [unjs/hookable ](https://github.com/unjs/hookable )
2022-01-27 17:02:42 +00:00
allowing different components to communicate with each other. You can think of it as **Builder Core** .
2022-11-16 10:04:28 +00:00
This context is globally available to be used with [nuxt/kit ](/docs/api/advanced/kit ) composables.
2022-01-27 17:02:42 +00:00
Therefore only one instance of Nuxt is allowed to run per process.
2022-11-16 10:04:28 +00:00
To extend the Nuxt interface and hook into different stages of the build process, we can use [Nuxt Modules ](/docs/guide/going-further/modules ).
2022-01-27 17:02:42 +00:00
2022-04-20 08:52:39 +00:00
For more details, check out [the source code ](https://github.com/nuxt/framework/blob/main/packages/nuxt/src/core/nuxt.ts ).
2022-01-27 17:02:42 +00:00
2022-08-13 07:27:04 +00:00
## The NuxtApp Interface
2022-01-27 17:02:42 +00:00
2022-04-16 13:53:36 +00:00
When rendering a page in the browser or on the server, a shared context will be created, referred to as `nuxtApp` .
2022-01-27 17:02:42 +00:00
This context keeps vue instance, runtime hooks, and internal states like ssrContext and payload for hydration.
You can think of it as **Runtime Core** .
2022-08-13 07:27:04 +00:00
This context can be accessed using `useNuxtApp()` composable within Nuxt plugins and `<script setup>` and vue composables.
2022-04-16 13:53:36 +00:00
Global usage is possible for the browser but not on the server, to avoid sharing context between users.
2022-01-27 17:02:42 +00:00
2022-11-16 10:04:28 +00:00
To extend the `nuxtApp` interface and hook into different stages or access contexts, we can use [Nuxt Plugins ](/docs/guide/directory-structure/plugins ).
2022-01-27 17:02:42 +00:00
2022-11-16 10:04:28 +00:00
Check [Nuxt App ](/docs/api/composables/use-nuxt-app ) for more information about this interface.
2022-01-27 17:02:42 +00:00
`nuxtApp` has the following properties:
Note: this is an internal interface, and some properties might change until stable release.
```js
const nuxtApp = {
2022-02-07 10:16:45 +00:00
vueApp, // the global Vue application: https://vuejs.org/api/application.html#application-api
2022-01-27 17:02:42 +00:00
// These let you call and add runtime NuxtApp hooks
2022-04-20 08:52:39 +00:00
// https://github.com/nuxt/framework/blob/main/packages/nuxt/src/app/nuxt.ts#L18
2022-01-27 17:02:42 +00:00
hooks,
hook,
callHook,
// Only accessible on server-side
ssrContext: {
url,
req,
res,
runtimeConfig,
noSSR,
},
// This will be stringified and passed from server to client
payload: {
serverRendered: true,
data: {},
state: {}
}
provide: (name: string, value: any) => void
}
```
2022-04-20 08:52:39 +00:00
For more details, check out [the source code ](https://github.com/nuxt/framework/blob/main/packages/nuxt/src/app/nuxt.ts ).
2022-01-27 17:02:42 +00:00
## Runtime Context vs. Build Context
Nuxt builds and bundles project using Node.js but also has a runtime side.
While both areas can be extended, that runtime context is isolated from build-time. Therefore, they are not supposed to share state, code, or context other than runtime configuration!
2022-11-16 10:04:28 +00:00
`nuxt.config` and [Nuxt Modules ](/docs/guide/going-further/modules ) can be used to extend the build context, and [Nuxt Plugins ](/docs/guide/directory-structure/plugins ) can be used to extend runtime.
2022-01-27 17:02:42 +00:00
2022-04-16 13:53:36 +00:00
When building an application for production, `nuxi build` will generate a standalone build
2022-11-16 10:04:28 +00:00
in the `.output` directory, independent of `nuxt.config` and [Nuxt modules ](/docs/guide/going-further/modules ).