/surrealdb-nuxt-starter

Primary LanguageTypeScriptMIT LicenseMIT

License Website

Nuxt 3 Minimal Starter

Look at the Nuxt 3 documentation to learn more.

Setup

Make sure to install the dependencies (this example uses pnpm). Specifically, we install the surrealdb.js package.

pnpm install

This tutorial assumes a SurrealDB server is running on http://localhost:8000. We used Docker, but feel free to use another installation method.

docker-compose up -d

Development Server

Start the development server on localhost:3000:

pnpm run dev

Run Dev

Result

Visit localhost:3000, to see the response printed on the server and browser:

Server: Hello World From SurrealDB

Run Dev

Under the code

Server-side Connection

To connect SurrealDB on your Nuxt project server side, copy the Nitro Server Plugin from the [.server/plugins] directory. This code creates a single connection to SurrealDB. To use the variable, import the surrealdb variable from the plugin in your server-side code.

Since this plugin works on server-side, we can store our configuration variables as private runtime variables in the Nuxt Config and can be overridden using environment variables.

The rest of this starter kit tests this connection by returning "Hello World From SurrealDB" and displaying it on our frontend. From here, create different API routes for any additional API functionality you need.

Contributing

See Contribution Guidelines.

What Next

Check out the deployment documentation to deploy on your favorite Cloud or Edge Provider.