Open In App

Localhost 3000

Last Updated : 07 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Localhost:3000 is a default port used by the web servers. It is a local development server that runs on port 3000. It is very commonly used by experienced as well as beginner and intermediate-level developers when they working on a web application. Developers use localhost:3000 to see the preview of the developed application and test it according to the requirements for responsiveness and other parameters before deploying it to production.

Let us understand localhost:3000 by breaking it down:

  • localhost: It refers to the hostname or the current device you are using for development purposes.
  • 3000: It is the port number on which the created development server is configured to listen.

Let us dive deeper into the concept of localhost:3000 by understanding the below points one by one:

How to start the localhost:3000 server on your machine?

To start the localhost:3000 server you must need to have a service that operates on the localhost:3000 port like ReactJS, NodeJS, VueJS, AngularJS, etc. If you are working with any of the mentioned services, then you need to type a command inside the terminal of your IDE or command prompt based on the service you are using.

Commands for different services are listed below:

  • Node.js: If you have node.js installed on your machine with Node Package Manager(npm). You can use the tools like http-server or live-server to start the localhost:3000 development server with the help of below commands:
// Install tools globally
npm install -g http-server/liver-server
// Navigate to your project
cd pathOfYourProject
// Start the server at port:3000
http-server/live-server -p 3000
  • ReactJS: In the case of ReactJS, you don’t need to install the server externally. If you are creating a react app using create-react-app it automatically creates a development server. You just need to run the below commands to start the server.
// Navigate to your project directory
cd pathOfYourProject
// Start the server
npm start
  • AngularJS: The angular app also comes with development server, you just need to create angular app using the Angular CLI and run the below commands.
// Navigate to your project directory
cd pathOfYourProject
// Start the server
ng serve
//By default, angular app run on port 4200 use below command to change it
ng serve --port 3000

How to create development server in ReactJS?

Follow the below steps to create and start development server in ReactJS:

  • Step 1: Create react app using the npm create-react-app command by specifying the name of the project after it.
npm create-react-app projectName
  • Step 2: Navigate to your current project folder.
cd pathToYourProject
  • Step 3: Create files inside the src folder and run the server using below command.
npm start

Example: The below code can be used as a template code for your file.

Javascript




// App.js file
 
import React, { useState } from 'react';
 
const App = ({ prop }) => {
    const [isHidden, setIsHidden] = useState(false)
    function btnClickHandler() {
        setIsHidden((prev) => !prev);
    }
 
    return (
        <div style={{ textAlign: 'center' }}>
            <h1 style={{ color: 'green' }}>GeeksforGeeks</h1>
            <h1>Hey {prop}!</h1>
            <h2>Welcome to GeeksforGeeks</h2>
            {
                isHidden &&
                <h3>A Computer Science Portal.</h3>
            }
            <button onClick={btnClickHandler}
                style={
                    {
                        backgroundColor: "green",
                        color: '#fff',
                        padding: '15px',
                        cursor: 'pointer',
                        border: 'none',
                        borderRadius: '10px'
                    }}>
                Click to toggle more page content
            </button>
            {
                isHidden &&
                <p>
                    This content is toggled dynamically using
                    click event with button.
                </p>
            }
        </div>
    );
};
 
export default App;


Output:

localhostGIF



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads