Coder Social home page Coder Social logo

impupindersingh / node-express-api-skeleton Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fusionalliance/node-express-api-skeleton

0.0 1.0 0.0 168 KB

The purpose of this API skeleton is to provide a starter API - one that is more complete than something you'd get from the Express application generator, and yet not bloated with a bunch of features you'll have to rip out.

JavaScript 100.00%

node-express-api-skeleton's Introduction

Fusion Node + Express API Skeleton

Purpose

The purpose of this API skeleton is to provide a starter API - one that is more complete than something you'd get from the Express application generator, and yet not bloated with a bunch of features you'll have to rip out.

The remainder of this document contains information needed to configure and run the API in a local development environment. It also include guidance for building upon this skeleton.

Instructions for deployment to a hosted environment are out of scope.

Prerequisites

  • Install Git.
  • Install Node.
  • Clone the Git repository to your local machine.
  • Make a copy of the .env.example file, and rename the copy to .env.
  • For Windows-based development environments only: Ensure line endings are configured for LF instead of CRLF. See the Troubleshooting section for instructions.

How To

Unless otherwise noted, all terminal commands must be issued from the project's root directory.

Install project libraries

npm install

Lint the code

npm run lint

You can also run the following to fix simple lint errors:

npm run fixlint

Run tests

npm test

Or you can run integration and unit tests separately:

npm run integration-test
npm run unit-test

Run the app

Execute the following to run the app in debug mode, with auto-restart functionality provided by nodemon:

npm run develop

Then browse to /api-docs to view all of the paths supported by the API.

Troubleshooting

Line endings are CRLF instead of LF (Windows only)

The line endings in this application are LF instead of CRLF. The commands below will configure your Windows environment for LF only. These changes will be applied to all of your Git Repos.

# Set default core.autocrlf to false in Windows
git config --global core.autocrlf false

# Set core.eol to LF in Windows
git config --global core.eol lf

Application or Tests Don't Work Due To Missing Dependencies

  • Re-run npm install to verify that your dependencies are up to date.

Debugging project locally with Visual Studio Code fails with 'Error: Required value not provided: appName'

A launch.json file is necessary to use environment variables from the .env file when debugging the project locally.

  • Create a launch.json file in the project's .vscode folder with the following JSON contents:
{
  "version": "0.2.0",
  "configurations": [

    {
      "type": "node",
      "request": "launch",
      "name": "Launch API",
      "program": "${workspaceFolder}/bin/www",
      "envFile":"${workspaceFolder}/.env"
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Run Tests",
      "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
      "args": [
        "-u",
        "tdd",
        "--timeout",
        "999999",
        "--colors",
        "${workspaceFolder}/tests/**/*.js"
      ],
      "internalConsoleOptions": "openOnSessionStart",
      "envFile":"${workspaceFolder}/.env"
    }
  ]
}

Notes: The supplied JSON code will add two debugging options, Launch API and Run Tests to the Visual Studio Code IDE:

  • Launch API will start the API. The default endpoint is localhost:3000/api

  • Run Tests will execute all Mocha test scripts in the project and show the results in the DEBUG CONSOLE window.

I go to http://localhost:3000/ and I get "Error: Not Found".

Everything Is Hosed!

Sometimes you just need to completely reset your development environment. Execute the following commands to start from a "clean slate":

// NOTE: Untracked changes will be lost!
git clean -dxf

Project Folder Structure

For the benefit of those building and/or maintaining the application, here's an overview of the folder structure.

root

Contains files common to typical Node+Express Web apps.

bin

Contains application startup code. Originally generated by the Express Application Generator, and then modularized and simplified.

src

Contains the application's source files.

app-middleware

Application middleware to handle crosscutting application-level concerns.

models

Contains Web models.

If you introduce different kinds of models (e.g., domain/data models), be sure to separate these using subfolders.

routes

The application route handlers.

services

Functions that provide support to other parts of the application, esp. to the route handlers.

tests

Automated tests.

Recommendation: Keep integration and unit tests separate. Recommendation: Keep tests separate from source files.

Versioning

We use SemVer for versioning.

node-express-api-skeleton's People

Contributors

camoore1979 avatar jacobking2 avatar jeremiahdotnet avatar korymarks avatar naptowncode avatar

Watchers

 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.