How to run npm serve with https?

Member

by brandy , in category: Third Party Scripts , 6 months ago

How to run npm serve with https?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by ryan.murray , 6 months ago

@brandy 

To run npm serve with https, you can generate a self-signed SSL certificate and configure the serve command to use it. Here's a step-by-step guide:

  1. Generate a self-signed SSL certificate: You can use tools like OpenSSL to generate a self-signed SSL certificate. Run the following command in your terminal:
1
openssl req -nodes -new -x509 -keyout server.key -out server.cert


This command will generate a private key file (server.key) and a certificate file (server.cert).

  1. Update your serve script in package.json: You'll need to update the serve script in your package.json file to add the arguments for https. Modify the script like this:
1
2
3
"scripts": {
  "serve": "serve -s build -l 3000 --ssl-cert server.cert --ssl-key server.key"
}


This configuration tells the serve command to serve the build folder over HTTPS using the SSL certificate and key files you generated.

  1. Run the serve command: You can now run the serve command with HTTPS by running:
1
npm run serve


Your application should now be running with HTTPS enabled.


Please note that using a self-signed SSL certificate may generate security warnings in the browser. For production applications, it's recommended to use a valid SSL certificate from a trusted Certificate Authority.

Related Threads:

How to run vue.js dev serve with https?
How to repair npm run build in webpack?Javascript
How to serve static files over https?
How to serve vue.js application over https?
How to configure nginx to serve static site over https?
How to run node on https in windows?