# nuxt-update

> Nuxt module: detect app update

Latest version **1.0.0** (published 2023-06-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install nuxt-update
pnpm add nuxt-update
yarn add nuxt-update
bun add nuxt-update
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-06-03 |
| First published | 2023-06-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ilya Semenov |
| Maintainers | ilyasemenov |

## Links

- npm: https://www.npmjs.com/package/nuxt-update
- npm.io page: https://npm.io/package/nuxt-update

## Dependencies (3)

- [defu](https://npm.io/package/defu.md) ^6
- [mitt](https://npm.io/package/mitt.md) ^3.0.0
- [@nuxt/kit](https://npm.io/package/@nuxt/kit.md) ^3.1.0

## Recent versions

- 1.0.0 (latest) — 2023-06-03

## README

# nuxt-update

Nuxt module that detects update to Nuxt app.

### Problem

When you publish updates, users won't get the new version until they hard refresh the browser page. Client-side navigation with `<nuxt-link>` doesn't trigger updates. Users may continue working with outdated versions of your app for days or even weeks.

### Solution

`nuxt-update` allows you to define app version, and then periodically checks on the client if the version has changed on the server. When an update is detected, an event is emitted which you can handle with some kind of user notifcation (or simply refresh the page automatically).

To save bandwidth and prevent unexpected network activity, updates are only checked during client-side navigation, with a customizeable minimum interval.

## Quick Setup

Install:

```sh
npm install nuxt-update
```

Add `nuxt-update` to the `modules` section of `nuxt.config.ts`:

```ts
export default defineNuxtConfig({
  modules: ["nuxt-update"],
})
```

Create `plugins/update.client.ts` with your own update handler:

```ts
export default defineNuxtPlugin(() => {
  const { $update } = useNuxtApp()
  $update.on("update", (version) => {
    // TODO: Use some fancy toast library.
    if (confirm(`New version ${version} available. Update?`)) {
      location.reload()
    }
  })
})
```

Define `NUXT_PUBLIC_UPDATE_VERSION` when starting Nuxt app:

```sh
export NUXT_PUBLIC_UPDATE_VERSION="1.2.3"
# or
export NUXT_PUBLIC_UPDATE_VERSION=$(git rev-parse --short HEAD)

npx nuxi start
```

## Module options

The following defaults are used:

```ts
export default defineNuxtConfig({
  modules: ["nuxt-update"],
  update: {
    // Minimum interval between update checks (in seconds).
    checkInterval: 60,
    // URL path where the current version is published.
    path: "/version.json",
  },
})
```

---
_Source: https://npm.io/package/nuxt-update · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
