I find myself trying to create a postgres database, so I installed postgres and started a server with initdb /usr/local/pgsql/data
, then I started that instance with postgres -D /usr/local/pgsql/data
now how can I interact with this through node? For example, what would the connectionstring
be, or how am I able to find out what it is.
Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up
Join them; it only takes a minute:
|
|||||||||
|
Here is an example I used to connect node.js to my Postgres database. The interface in node.js that I used can be found here https://github.com/brianc/node-postgres
|
|||||||||||||||||||||
|
A simple approach: pg-promise, if you are familiar with promises that is ;)
|
|||||||||||||||||||||
|
Just to add a different option - I use Node-DBI to connect to PG, but also due to the ability to talk to MySQL and sqlite. Node-DBI also includes functionality to build a select statement, which is handy for doing dynamic stuff on the fly. Quick sample (using config information stored in another file):
config.js:
|
|||||
|