In full-stack development, speed and efficiency matter. Thatās where Bolt.new comes ināa game-changing AI tool that helps you build Nuxt apps, generate APIs, and design UIs in no time. By leveraging AI, it simplifies the coding process, so you can focus on creating and deploying powerful applications faster than ever. Ready to see how it works? Letās dive into building a full-stack Nuxt app with Bolt.new!
bolt.new, developed by the StackBlitz team, is an amazing and powerful AI tool designed to streamline web development by automating code generation. This tool makes it easier to build both front-end and back-end logic without the need for extensive manual coding.
It supports popular frameworks like Nuxt, Vue, React, and Astro, allowing you to quickly create dynamic UIs, generate API endpoints, and handle complex full-stack development tasks. By leveraging AI, Bolt.new accelerates your workflow and eliminates the repetitive coding tasks that slow down your progress.
Bolt.new also makes integrating persistent storage easier with tools like Nitroās useStorage function, enabling smooth data management in your applications. This makes it an ideal tool for developers who want to quickly spin up projects without sacrificing flexibility or control.
In this article, weāll explore how to use Bolt.new to create a Nuxt-based blog, showcasing its ability to handle both front-end UI generation and back-end API management. Letās dive in and see how well it performs in real-world development scenarios.
Letās start the Nuxt project by prompting bolt to create a blog for us with the following prompt:
Let's create a blog about video games using Nuxt and Nuxt Content.
It should use TailwindCSS for styling and have a cool, modern gamer vibe.
This produces a stylish and functional starting point that even has some relevant dummy posts! It has a homepage, a blog listing page, and a post page that uses a dynamic slug parameter to fetch the proper post all setup properly to manage content with Nuxt Content.
The images are currently all broken. Letās add in some placeholder images from lorem picsum.
use placeholder images from lorem picsum for all the images
Currently each of the blog posts has a published at date that is absolute like 4/2/2024
. What if we wanted to make the times relative. We can definitely do that! I just so happen to know that VueUse has a great composable for this, so letās see if Bolt uses it.
Can we make the date display relative (like 1 day ago, etc)
and then only show the human readable date on hover? Use the `useTimeAgo`
composable from the VueUse Nuxt module.
This does the trick! Bolt installs the VueUse Nuxt module and even creates an abstracted RelativeDate
component and puts it into place in the blog post page.
There were a couple hang ups in this step though, an extra <content>
tag got randomly added to the [...slug]
component (presumably this is used by Bolt under the hood when generating new content) and since bolt had to run npm install, the dev server stopped. Both were easily fixed with a little manual attention though.
At this point, weāve got a decently functional blog. Letās use the useStorage
function from nitro to support key-value storage (or KV storage) for post comments.
The useStorage
function abstracts the KV storage services provided by various hosting platforms, including Cloudflare's KV, Netlifyās Blob Storage, and Vercel's KV storage. This abstraction offers flexibility, allowing us to deploy our applications across multiple platforms. For development, we'll use in-memory storage to simulate data persistence without external dependencies.
Add comments support to the single blog post page.
Create an API endpoints to get and store comments.
In the API endpoints, use the useStorage function from Nitro
to store comments in KV storage.
This prompt getās a pretty nice UI bootstrapped and writes the code for a couple API endpoints.
When trying to post a comment, though I get an error that crypto is not defined.
The node version running in bolt.new is Node 18, so the crypto module isnāt available. Itās being used in the API endpoint for creating new comments to generate a random UUID. No problem, I can install nanoid
with the terminal tab and generate a UUID that way instead.
This time it works! Even when I refresh the page, my comment sticks around because itās persisted to the running node applicationās memory. When deploying Iād simply need to configure the KV storage driver of my choice in nuxt.config.ts
Plain text comments are fine, but supporting rich text with options like bold and italic would be even nicer. TipTap editor can take care of that no problem!
Provide rich text support for comments with tip tap.
It even escapes the HTML output by TipTap to prevent malicious JavaScript injection and uses the Tailwind typography plugin to style the output.
Letās try making this just a little more complicated by implementing authentication with Nuxt Auth Utils. This means that users will have to login with github to make a comment. Iām also going to hint to bolt where to find docs for Nuxt auth utils as itās pretty new and I want to make sure bolt handles things accurately.
Let's implement authentication with Nuxt Auth Utils
(https://github.com/atinux/nuxt-auth-utils) and require a user
to login with github to make a comment.
This time I get mixed resultsā¦.
The UI looks great!
A Sign-In link was added the the main nav
Bolt walks me through the setup needed on the Github side and even gives me placeholders for the needed env vars
Some things donāt go quite as wellā¦ There are several errors I have to fix manually with the help of the Nuxt auth utils docs, including:
useAuth
to the proper useUserSession()
composable..env
vars as required by the Nuxt Auth Utils docs (NUXT_OAUTH_GITHUB_CLIENT_SECRET and NUXT_OAUTH_GITHUB_CLIENT_ID)Even after making these changes, auth still didnāt quite work so I stopped trying and asked bolt to revert the auth feature:
the nuxt auth utils didn't work, let's roll that back
and too be fair it did a good job rolling things back to the previous state, I only had to delete one file manually (that is server side route I added manually above to handle github auth)
Here are all my prompts I used to generate the finished project. This easy copy was made possible with a bookmarklet shared by StackBlitz engineer Tomek SuÅkowski.
Let's create a blog about video games using Nuxt and Nuxt Content. It should use TailwindCSS for styling and have a cool, modern gamer vibe.
use placeholder images from lorem picsum for all the images
Can we make the date display relative (like 1 day ago, etc)
and then only show the human readable date on hover? Use the useTimeAgo
composable from the VueUse Nuxt module.
Add comments support to the single blog post page. Create an API endpoints to get and store comments. In the API endpoints, use the useStorage function from Nitro to store comments in KV storage.
Provide rich text support for comments with tip tap.
Let's implement authentication with Nuxt Auth Utils (https://github.com/atinux/nuxt-auth-utils) and require a user to login with github to make a comment.
the nuxt auth utils didn't work, let's roll that back
In my experience, Bolt.new is the best way to generate code from scratch when working on a new web application or app. It certainly isnāt perfect but is a huge step forward. Besides this example blog, Iāve been experimenting with it for other purposes and found the following practices to be helpful:
Our goal is to be the number one source of Vue.js knowledge for all skill levels. We offer the knowledge of our industry leaders through awesome video courses for a ridiculously low price.
More than 200.000 users have already joined us. You are welcome too!
Ā© All rights reserved. Made with ā¤ļø by BitterBrains, Inc.