Run a Node.js app
- Add postgres client to your project. In this example we used postgres.js, but feel free to choose another one
- Store your Neon credentials somewhere, for example in the
.env
file.
NEON_HOST=...
NEON_DB=...
NEON_USER=...
NEON_PASS=...
NEON_PORT=...` \
- To connect to the database using postgres client and your Neon credentials, add the following code to the
pages/api/hello_worlds.js
import postgres from 'postgres';
const sql = postgres({
host: process.env.NEON_HOST,
port: process.env.NEON_PORT,
database: process.env.NEON_DB,
username: process.env.NEON_USER,
password: process.env.NEON_PASS,
});
const result = await sql.uafe(req.body);