Skip to content

Latest commit

 

History

History

.github

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Api List Path

ExpressJS example server and client API

Byte size of Api List Path Open Issues Open Pull Requests Latest commits



Requirements

NodeJS and NPM are utilized by this project to track and install dependencies, check the official Downloading and installing Node.js and npm guide for details.


Quick Start

Clone Project

mkdir -vp ~/git/hub/web-dev-examples

cd ~/git/hub/web-dev-examples

git clone [email protected]:web-dev-examples/api-list-path.git

Install All Dependencies (option 1)

npm install

Install Development Dependencies (option 2)

npm install --only=dev

Install Production Dependencies (option 3)

npm install --production

Run ExpressJS Server

npm run start

Navigate to http://localhost:8080/ within a web-browser to interact with API via UI, or send Curl commands similar to...

curl --data 'path=.' --url 'http://localhost:8080/list'

Usage

After editing files under ts/ directory transpile JavaScript via...

npm run ts-build

Setup Notes

Steps preformed to construct this project


Initialize Version Management

git init api-list-path

cd api-list-path

Development Dependencies

npm install --save-dev @types/express\
                       @types/node\
                       nodemon\
                       typescript

App Dependencies

npm install --save body-parser express

Directory/File Structure

touch .gitignore


touch tsconfig.json
touch tsconfig.back-end.json
touch tsconfig.front-end.json


mkdir -p ts/back-end/routes/list
touch ts/back-end/index.ts
touch ts/back-end/routes/index.ts
touch ts/back-end/routes/list/post.ts


mkdir -p front-end/assets/js
touch front-end/index.html


mkdir -p ts/front-end/assets/js
touch ts/front-end/assets/js/index.ts

Overview

Check the "script" key for available npm run <target> options


  • .gitignore configures directory/file patterns that Git should ignore from version control by default.

Ignored directories and/or files can be added via -f or --force option, eg...

git add -f ignored-file.ext

Multi-configuration setups with TypeScript can be a bit tricky; the main tsconfig.json should contain configurations shared by all projects, and any project specific files should then overwrite and/or add further customization.

tsconfig.back-end.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "back-end",
    "lib": [ "es2017" ],
    "esModuleInterop": true,
    "moduleResolution": "node",
    "module": "commonjs"
  },
  "include": [
    "ts/back-end/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "ts/front-end",
    "ts/jest"
  ]
}

The "outDir" key defines where transpiled JavaScript files will be saved

The "include" key defines a list of directory/file paths that will be transpiled by current configurations

The "exclude" key defines a list of directory/file paths that should not be transpiled by current configurations

package.json (snip)

{
  /* ... */
  "scripts": {
    "nodemon": "nodemon back-end/index.js",
    "start": "node back-end/index.js",
    "ts-build-back-end": "tsc --project tsconfig.back-end.json",
    "ts-watch-back-end": "tsc --project tsconfig.back-end.json ts/back-end --watch",
  },
  /* ... */
}

The --project parameter of tsc commands defines a configuration file to be used for transpiling


For a small applications this level of organization may be excessive, however, for larger projects splitting responsibilities into separate directories and/or files can be helpful.

TypeScript files for back-end server may be transpiled via npm run script targets...

npm run ts-build-back-end

... which will output transpiled JavaScript files to the back-end directory


Currently the front-end code for web-browsers is not pretty, but is functional.


Contributing

Options for contributing to api-list-path and web-dev-examples


Forking

Start making a Fork of this repository to an account that you have write permissions for.

cd ~/git/hub/web-dev-examples/api-list-path

git remote add fork [email protected]:<NAME>/api-list-path.git
  • Commit your changes and push to your fork, eg. to fix an issue...
cd ~/git/hub/web-dev-examples/api-list-path


git commit -F- <<'EOF'
:bug: Fixes #42 Issue


**Edits**


- `<SCRIPT-NAME>` script, fixes some bug reported in issue
EOF


git push fork main

Note, the -u option may be used to set fork as the default remote, eg. git push -u fork main however, this will also default the fork remote for pulling from too! Meaning that pulling updates from origin must be done explicitly, eg. git pull origin main

  • Then on GitHub submit a Pull Request through the Web-UI, the URL syntax is https://github.com/<NAME>/<REPO>/pull/new/<BRANCH>

Note; to decrease the chances of your Pull Request needing modifications before being accepted, please check the dot-github repository for detailed contributing guidelines.


Sponsor

Thanks for even considering it!

Via Liberapay you may [![sponsor__shields_io__liberapay]][sponsor__link__liberapay] on a repeating basis.

Regardless of if you're able to financially support projects such as api-list-path that web-dev-examples maintains, please consider sharing projects that are useful with others, because one of the goals of maintaining Open Source repositories is to provide value to the community.


Attribution


License

ExpressJS example server and client API
Copyright (C) 2020 S0AndS0

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

For further details review full length version of AGPL-3.0 License.