Giter VIP home page Giter VIP logo

node_express_starter's Introduction

Node Express Starter


Video Walkthrough => https://www.loom.com/share/b1a7cbc0f57444a281047eba2c42fe1c

A barebones node express app with some basic CRUD operations using an object in place of a database. Includes unit tests using supertest https://www.npmjs.com/package/supertest


Architecture


This app uses a common pattern of having controllers and routes in separate folders.

Controllers are used to manipulate and query data.

Routes simply listen for requests on certain paths and provide methods which are called on those routes.

Middlewares are methods that are called before the request goes to a controller. In this app, we have a validateUserBody middleware which ensures all incoming requests have an id property - if they DO NOT, we simply reject the request - if they DO, we continue the request using next


Getting Started


npm install

npm start

npm run dev to start with hot reloading

npm test


How To Use


You'll see many comments throughout the codebase which highlight common patterns and libraries.

There are 4 routes you can reach from your localhost like so:

[GET] http://localhost:5000/user

[POST] http://localhost:5000/user

[PUT] http://localhost:5000/user

[DELETE] http://localhost:5000/user

Examples:

To create a new user [POST] http://localhost:5000/user

Payload:

{
    "id": "123",
    "email": "[email protected]",
    "name": "brian"
}

To get a user with an id of 123: http://localhost:5000/user/123


Further Reading


CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

REST Architecture: https://restfulapi.net/


Next Steps


You can create a true database connection to persist your data and add new routes, controllers and middlewares.

node_express_starter's People

Contributors

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