An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Express-postgres-mapbox example

![Example screenshot](/screenshot.png)

## 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