Choose your preferred package manager to install Nuxt Content v3:
pnpm add @nuxt/content
yarn add @nuxt/content
npm install @nuxt/content
bun add @nuxt/content
Add the Nuxt Content module to your nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@nuxt/content']
})
When starting a new Nuxt project with the create-nuxt CLI, you can simply select @nuxt/content from the interactive module selector. This will automatically install and register the module for you.
npm create nuxt <project-name>
yarn create nuxt <project-name>
pnpm create nuxt <project-name>
bun create nuxt <project-name>
deno -A npm:create-nuxt@latest <project-name>
better-sqlite3 or sqlite3 package.experimental.nativeSqlite configuration.Create a content.config.ts file in your project root directory:
import { defineContentConfig, defineCollection } from '@nuxt/content'
export default defineContentConfig({
collections: {
content: defineCollection({
type: 'page',
source: '**/*.md'
})
}
})
This configuration creates a default content collection that processes all Markdown files located in the content folder of your project. You can customize the collection settings based on your needs.
type: page means there is a 1-to-1 relationship between content files and pages on your site.Create a content/index.md file in your project root directory:
# My First Page
Here is some content.
Read more about writing Markdown pages.
Create a pages/index.vue file and display the page content:
<script setup lang="ts">
const { data: home } = await useAsyncData(() => queryCollection('content').path('/').first())
useSeoMeta({
title: home.value?.title,
description: home.value?.description
})
</script>
<template>
<ContentRenderer v-if="home" :value="home" />
<div v-else>Home not found</div>
</template>
pages directory, you also need to update the app.vue file to allow rendering the pages by adding the NuxtPage component. (If you already have some pages in your project, you are good to go.)<template>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</template>