This is another demo express application. How would I (Jarrett Meyer) build an Express application from scratch? The sample application in question is a simple document sharing database. Users can create and upload documents. Documents that are published are publicly visible.
The application runs inside of a Vagrant VM. After you clone the project, run vagrant up
from you command line to build the virtual machine.
The VM contains everything you need to build and run the application.
- Postgres 9.5.1
- NodeJS 5.7.0
- All necessary global npm packages required by the command line.
From inside the VM...
$ cd /vagrant
$ npm start
Or, if you would like to make changes and see the changes without restarts, use nodemon. This will run your start
script automatically for you.
$ nodemon --watch server
Check to see if the application is up.
response body:
{
status: "server is up",
timestamp:1457577707037
}
Login to the application.
POST body:
{
email: <user_email>,
password: <user_password>
}
response:
{
token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3N1ZWQiOjE0NTc1Nzc4NTQwOTksImV4cGlyZXMiOjE0NTk5OTcwNTQwOTl9.dsjbWnQIxvkTFRoXN3pC8euW2HLoPVsHiUdI9Tgjp8s"
}
Get all documents that are visible to the user. This will include all of the user's documents and all documents from other users that have been flagged as published. User must be authenticated.
response body:
{
documents: [{
id: 1,
ownerId: 2,
title: "Fixture document #1",
abstract: "Fixture document #1",
type: "text/plain",
published: true
}, {
id":3,
ownerId: 4,
title: "Fixture document #4",
abstract: "Fixture document #4.",
type: "text/plain",
published: true
}, {
/* snip */
}]
}
Get a document by id. User must be authenticated. The document must be published, or the document must belong to the current user.
response body:
{
document: {
id: 1,
ownerId: 2,
title: "Fixture document #1",
abstract: "Fixture document #1",
type: "text/plain",
published: true
}
}
Create a new document.
The the file attachment for a document.
Attach a file to a document. A document can have exactly one file associated with it. A user can attach a file only if a user owns the document.
Update a document. User must be authenticated. A user can update a document only if the user owns the document.
Get all owners. User must be authenticated.
response body:
{
owners: [{
id: 2,
displayName: "Alice A",
email: "alice@example.com"
}, {
id: 4,
displayName: "Claire C",
email: "claire@example.com"
}, {
/* snip */
}]
}
Get an owner by id. User must be authenticated.
response body:
{
owner: {
id: 4,
displayName: "Claire C",
email: "claire@example.com"
}
}
Get a list of all users in the application. This is only allowed if the user is an administrator.
response body:
{
users: [{
id: 2,
displayName: "Alice A",
email: "alice@example.com",
admin: false,
tokenIssuedAt: "2016-03-10T11:05:48.532Z"
}, {
id: 3,
displayName: "Betty B",
email: "betty@example.com",
admin: false,
tokenIssuedAt: "2016-02-16T18:43:12.630Z"
}, {
/* snip */
}]
}
$ npm test