Skip to content

Main #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/node_modules
/node_modules
.cache.md
SECURITY.md
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ brew services start postgresql
psql postgres
```


```sql
CREATE ROLE me WITH LOGIN PASSWORD 'password';
ALTER ROLE me CREATEDB;
Expand All @@ -34,7 +35,15 @@ INSERT INTO users (name, email)
VALUES ('Jerry', 'jerry@example.com'), ('George', 'george@example.com');
```

## Installation
## Installation for Mac

> Currently tested with [Postgres.app](https://postgresapp.com/downloads.html)

Applications are ran with group `wheel` in Mac. Applications and Users in that group have elevated `su` permissions.

## Installation for Windows

> Don't forget to edit `pg_hba.conf` in order to allow server connections to postgres if on the same machine!

```bash
git clone git@github.com:taniarascia/node-api-postgres
Expand All @@ -43,6 +52,17 @@ npm install
node index.js
```

## Usage

```bash
node index.js -U 'me' -p 'password'
```






## Commands

- GET: `curl http://localhost:3000/users`
Expand All @@ -57,3 +77,4 @@ node index.js
## License

This project is open source and available under the [MIT License](LICENSE).

17 changes: 10 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const db = require('./queries')
const port = 3000
"use strict";

app.use(bodyParser.json())
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const db = require('./queries');
const port = 3000;
const fs = require('fs');

app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: true,
})
)
);

app.get('/', (request, response) => {
response.json({ info: 'Node.js, Express, and Postgres API' })
Expand Down
147 changes: 89 additions & 58 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"license": "MIT",
"dependencies": {
"express": "^4.16.3",
"pg": "^7.4.3"
"pg": "8.7.1"
}
}
35 changes: 35 additions & 0 deletions parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";

module.exports = (function () {
function Parser(argsList){
this.argsList = argsList.map(function (a) {
return a;
})
}

/**
* @description If cli detects hyphen for -U return the element ahead of it
* @return {number} Default user is me
*/
Parser.prototype.getPgUser = function (credentials) {
if (this.argsList.indexOf("-U") !== -1) {
return this.argsList[this.argsList.indexOf("-U") + 1]
}

return 'me';
};

/**
* @description If cli detects hyphen for -p retrieve password in the element ahead
* @return {number} Default pw is password
*/
Parser.prototype.getPgPassword = function (credentials) {
if (this.argsList.indexOf("-p") !== -1) {
return this.argsList[this.argsList.indexOf("-p") + 1]
}

return 'password'
};

return Parser;
})()
Loading