Giter VIP home page Giter VIP logo

express-js-starter-app's Introduction

Express.js Starter App

Concept

This project shows some basic usage of Express.js features, including:

  • handling incoming HTTP requests using express routes
  • exploring the purpose of middleware and how it works
  • debugging express apps using morgan and Postman
  • handling data included in HTTP POST requests
  • handling file uploads using multer
  • making requests from express to external APIs with axios and serving the data to the client
  • setting environmental variables using dotenv
  • use of a .gitignore file to exclude 3rd-party code and autogenerated files from version control tracking
  • use of a package.json with npm to track dependencies and streamline installation.

Many of the features of Express exhibited in this project are explained at a high level in this prepared lecture presentation.

Intentional exclusions

There are some common practices that we have not included here, since we believe they are distraction's from a beginner's ability to master Express.js' code patterns.

  • exclusion of any front-end code
  • exclusion of user account registration or log in functionality
  • exclusion of unit testing modules, like mocha and chai
  • exclusion of any database
  • exclusion of express-router, which would allow us to better organize large collections of routes

Available Scripts

In the project directory, you can run:

  • npm install - installs all the dependencies listed in the package.json configuration file. This is necessary before running the app, since the 3rd-party dependency code is excluded from version control by the .gitignore git settings file.

  • npm start - starts the server the old-fashioned way. When started in this way, the server has to be manually restarted whenever you change the code.

  • nodemon server - starts up the server with a monitoring process that will stop and restart the server automatically anytime there is a code change. If you haven't yet done so, install nodemon globally with npm install -g nodemon.

Once started, the server will by default be available on port 3000 of the local computer at the URL, http://localhost:3000.

Server API End-Points

This server code sets up routes for several API end-points - URLs to which a client can make requests. Except where indicated, the server accepts GET requests to these routes.

The example routes include:

  • / - a route for the "root" document - usually the home page, but in this case a simple text response.
  • /html-example - a route that shows how to return a simple HTML document.
  • /static/css/main.css - a route that servers as an example of servnig a static file that does not need dynamic server logic.
  • /json-example - a route that shows how the server can respond with a JSON document.
  • /middleware-example - a route that exhibits the concept of middleware.
  • /post-example - a route that accepts POST requests with some content the server expects the client to send in the body of the request.
  • /upload-example - a route that accepts a POST request with one or more files in the request that the client uploads to the server.
  • /proxy-example - a route that causes the server to make a request to a different API and then respond to the client with the data received from that API.
  • /dotenv-example - a route that shows how a server can use the dotenv module to load environmental variables from a file named .env into Javascript code.
  • /parameter-example/22 - a route that shows an example of how parts of the route URL - in this case the number 22 - can be parameterized and accessed in code.

Running the server

Testing the routes

It is possible to try out the routes directly in a web browser. However, it is often more convenient to use an API-testing tool like Postman to test out the server API end-points.

  • Import the test file named express-js-starter-app.postman_collection.json into Postman to test out the API end-points.

express-js-starter-app's People

Contributors

bloombar 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.