by Sai gowtham

How to change a port number in Gatsby

In this tutorial, we are going to learn about how to change a default port number (8000) in gatsby project.

Changing the port number

  1. Open the gatsby project in your favorite code editor.
  2. Navigate to package.json file and add the following config to gatsby develop command.
package.json
{
  "name": "gatsby-starter",
  "private": true,
  "description": "A starter for Gatsby",
  "version": "0.1.0",
  "license": "0BSD",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop -p 3500",

Here I set a port number 3500 using -p flag.

  1. Start the development server by running the npm run develop command, your port number is changed successfully.
You can now view gatsby-starter in the browser.
⠀
  http://localhost:3500/
⠀
View GraphiQL, an in-browser IDE, to explore your site's data and schema
⠀
  http://localhost:3500/___graphql
⠀
Note that the development build is not optimized.
To create a production build, use gatsby build

If you want to change a port number temporarily, you need to add a -p flag with the port number to the gatsby develop command.

gatsby develop -p 3500

or

gatsby develop --port 3500

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
130,921 students enrolled
21 hours of video content
View Course