Login to your Neon account, then click Create a project:
Fill out the fields:
- Name: Any.
- Postgres version: If you need to use the database with other software, 14 provides better compatibility. Else, use the default of 15.
- Region: Choose any US region for lower latency.
Your settings should look similar to the following:
You should then get a dialog with connection details. Select the PostgreSQL connection URL highlighted in green without the quotation marks around it, then copy it:
Go to val.town, click on your profile picture and click Secrets.
Click New secret, then set the key to a name you’d like to use to reference the secret and the value to the connection URL you just copied:
You can then use deno-postgres to connect to the database like so:
Note that you might need to change the secret name according to the key you set earlier.
While writing your code, remember that you should use prepared statements for any queries containing user data (or any query that has to change with new data) to prevent SQL injection attacks. You can find the 3 ways of going about this at https://deno-postgres.com/#/?id=prepared-statements-and-query-arguments.