https://github.com/moonwave99/express-postgres-mapbox-example
Express / postgres / mapbox example
https://github.com/moonwave99/express-postgres-mapbox-example
Last synced: 11 days ago
JSON representation
Express / postgres / mapbox example
- Host: GitHub
- URL: https://github.com/moonwave99/express-postgres-mapbox-example
- Owner: moonwave99
- Created: 2021-07-29T08:29:49.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-08-10T13:53:24.000Z (almost 5 years ago)
- Last Synced: 2025-03-06T06:46:51.690Z (over 1 year ago)
- Language: JavaScript
- Size: 2.02 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Express-postgres-mapbox example

## Starting
First, create and populate the db:
```
$ createdb express-postgres-mapbox-example
$ npm run db:init
```
Then create a `secrets.json` file with:
```json
{
"DATABASE_USERNAME": "your database username",
"DATABASE_PASSWORD": "your database password",
"MAPBOX_ACCESS_TOKEN": "your mapbox access token"
}
```
Finally:
```
$ npm start
```
And visit http://localhost:3000!
## Storing GeoJSON inside the database
Since we need it just for storage and not for querying, the [`jsonb` postgres type][jsonb] is enough:
```js
function updateItineraryById({ id, geometry }) {
return db
.query(
"UPDATE itineraries SET geometry = ($2)::jsonb WHERE id = $1 RETURNING *",
[id, JSON.stringify(geometry)]
)
.then((result) => result.rows[0]);
}
```
[jsonb]: https://www.postgresql.org/docs/12/functions-json.html