選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
Blaine Motsinger 5377db436f added console.log output if error in the routes 1年前
bin version 1.0.0 1年前
config working on notes db model 1年前
db version 1.0.0 1年前
models finished notes db model 1年前
routes added console.log output if error in the routes 1年前
views added conversion of datetime to template 1年前
.gitignore version 1.0.0 1年前
README.md corrected version type 1年前
dbh.js finished notes db model 1年前
package.json finished notes db model 1年前
server.js finished notes db model 1年前

README.md

notes

web app and api in nodejs

VERSION

1.0.1

REQUIREMENTS

node, npm, and the dependencies listed below.

DEPENDENCIES

  • express ^4.16.3
  • knex ^0.15.2
  • moment ^2.22.2
  • path ^0.12.7
  • pug ^2.0.3
  • sqlite3 ^4.0.2
  • commander ^2.17.1

SETUP

Clone the source code

$ git clone https://github.com/renderorange/notes.git

Install the dependencies

$ cd notes/
$ npm install

Create the .notesrc file within the project dir

$ vi .notesrc

The rc file should contain the following pieces of information

{
    "app": {
        "port": 5000,
        "address": "0.0.0.0"
    }
}

RUNNING THE APP

After installing and configuring the app it’s ready to be run by node.

$ node notes.js 
[12052018-175008] [info] notes - version 1.0.1
[12052018-175008] [info] server started
[12052018-175008] [info] serving: 0.0.0.0:5000

The server will log request information to stdout as they happen.

[12052018-175418] 127.0.0.1 GET /api/notes 
[12052018-175437] 127.0.0.1 GET / 

ROUTES AND RESPONSES

The app and api contain the following routes:

/

The index route returns a 200 OK, in text/html, containing the notes from the db, processed through the pug template engine.

$ curl -i localhost:5000/
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 228
Date: Thu, 06 Dec 2018 00:06:22 GMT
Connection: keep-alive

<!DOCTYPE html><html lang="en"><head><title>Notes</title></head><body><div id="notes"><p class="note">12/5/2018, 6:05:20 PM - Hello, World!</p><p class="note">12/5/2018, 6:05:58 PM - more olives on the pizza.</p></div></body></html>
[12052018-180622] 127.0.0.1 GET /

EXCEPTIONS

The index route will return a 500 error, in text/plain, containing the string “Database Error”, if the query to fetch the notes fails.

/api/notes

The notes route within the api path returns a 200 OK, in application/json, containing the notes from the db, in a well-formed json data structure.

$ curl -i localhost:5000/api/notes
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 147
Date: Thu, 06 Dec 2018 00:13:18 GMT
Connection: keep-alive

[
   {
      "created_at" : "2018-12-06 00:05:20",
      "note" : "Hello, World!",
      "id" : 1
   },
   {
      "created_at" : "2018-12-06 00:05:58",
      "note" : "more olives on the pizza.",
      "id" : 2
   }
]
[12052018-181318] 127.0.0.1 GET /api/notes

EXCEPTIONS

The notes route within the api path will return a 500 error, in text/plain, containing the string “Database Error”, if the query to fetch the notes fails.

*

The default route will return a 404 Not Found, in text/plain.

This route is triggered for anything requested which is not defined and loaded.

$ curl -i localhost:5000/notfound
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Content-Length: 9
Date: Wed, 05 Dec 2018 23:57:30 GMT
Connection: keep-alive

Not Found
[12052018-175730] 127.0.0.1 GET /notfound 

ADDITIONAL SCRIPTS AND CONFIGURATION FILES

This project also contains some additional scripts and configuration files to help in testing and administration.

bin/add_note

The add_note script can be used to add notes directly to the database.

$ ./add_note 
Usage: add_note <note>

Options:
  -V, --version  output the version number
  -h, --help     output usage information

The dependencies will need to be installed within the bin directory before using it.

$ cd bin/
$ npm install

backup_db.bash

The backup_db.bash script can be used to make backups of the sqlite3 database.

$ ./backup_db.bash 
# SCRIPT_DIR ----- .
# BACKUP_DIR ----- ./../db/backup
# DATABASE_NAME -- notes.db
# BACKUP_NAME ---- notes.db.120518.back

# backing up database into ./../db/backup - done

The backup directory will need to be created within the db directory before using it.

$ cd db/
$ mkdir backup

The backup directory is excluded from the git repo and will not be watched if it’s present.

config/services

There are a number of sample configuration files within the config/services directory which can be used for running the app through apache and systemd.

AUTHOR

Blaine Motsinger - blaine@renderorange.com