Giter Site home page Giter Site logo

practice-for-week-10-intro-to-express's Introduction

Basic Phase 1: Initialize an Express Application

In this phase, you will create a new Express project and initialize an Express application to listen for requests on a port. You will also return a simple text response on the /status route.

Create a new Express project

cd into the server directory after creating it.

Add a package.json file by running the following command:

npm init -y

Install the following dependencies using the command npm install:

  • express

Install the following development dependencies using the command npm install -D:

  • nodemon

Create an Express application

Create a file called app.js inside of your server folder.

Initialize an Express application inside that file.

Establish listener

Create a port variable and set it to a desired port for your Express application like 5000.

Allow the initialized Express application to listen for requests at the port you set to the port variable. Your application should log something like "Server is listening on port <port number>" when the server successfully connects to the port.

Add scripts to start the server

Create a script in the package.json file to start the server in production using node. The script can be named "start".

Create another script to start the server in development using the nodemon package. nodemon allows the server to automatically restart whenever any server files get updated. This script can be called "dev".

Test your server

Start your server in development using one of the package.json scripts.

Check to see if you set things up correctly by navigating to the appropriate URL for accessing the root URL for the Express server in the browser.

You should see the generic Express error message of Cannot GET / because you have not created a route handler for GET / yet.

Make route with text response

Create a route handler for the GET protocol at the route /status. Send a plain text response using res.send() with text like "The server is alive!".

Test your new route in the browser by adding /status after the port number in the address bar.

If all is working properly, your browser will show

The server is alive!

practice-for-week-10-intro-to-express's People

Contributors

aa-assessment-project-manager[bot] avatar ahmedmaher2481998 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.