Skip to content

How to do it (locally) ?

Ayoub FATIHI edited this page Feb 28, 2022 · 1 revision

You can use the code from this repo, but ensure you have :

  • Postgres and postgis with a populated database
  • Nodejs with pg, express and body-parser packages installed

See below for details.

1. Download the code from this repo

2. Prepare the frontend i.e a website

Build your web page

3. Prepare the backend

For the back end, we will be using nodejs for the server language and postgresql for our database because it supports PostGIS extension.

a. Prepare your database (Postgres and PostGIS) on your laptop

  • Install Postgresql from here
  • Activate PostGIS by running CREATE EXTENSION postgis;
  • Populate your databse Screenshot_20220224_112838

b. Install nodejs

  1. Install nodejs from here.

  2. Init your project by running and complete setup:

npm init
  1. Install from terminal (PowerShell or cmd for Windows, bash,...) the needed npm packages :
npm install pg
npm install express
npm install body-parser
  1. Setup connection by changing connections.js parameters to your personal ones.
  2. Run to launch your app by running:
node index.js

Screenshot_20220224_112945

  1. Enjoy your app at : http://localhost:3000/.

  2. For these spatial queries please fetch the geometry as GeoJSON and alias geom as: ST_AsGeoJSON(geom) AS geom

  3. Try like this query (maroc table needed to be in your db):

SELECT id, ST_AsGeoJSON(geom) AS geom FROM maroc

ezgif-5-cb393bb8b4