
Step 1: Install mkcert
We'll be using mkcert which is a "simple tool for making locally-trusted development certificates" and what's nice about it is that it requires zero configuration. If you are using macOS and have Homebrew installed, do run the command below.
brew install mkcert brew install nss # if you use Firefox mkcert -install
Step 2Generate certificate
Once you have installed mkcert, we'll have to generate the certificate now by running the command below.
mkcert -key-file key.pem -cert-file cert.pem localhost
Step 3: Nuxt Config
The next step is to add some configuration for nuxt.config.js and the config would be under the "server" property.
import path from 'path' import fs from 'fs' const config = {} if (process.env.NODE_ENV === "development") { config.server = { https: { key: fs.readFileSync(path.resolve(__dirname, 'key.pem')), cert: fs.readFileSync(path.resolve(__dirname, 'cert.pem')) } } } export default config
Step 4: Package.json
"scripts": { "dev": "export NODE_TLS_REJECT_UNAUTHORIZED=0 && nuxt --env.NODE_TLS_REJECT_UNAUTHORIZED=0", }
Do note that you can update the host and port too if preferable. Now open the link in your browser and you should be able to see that the localhost is now served securely.