An example backend for a social news site.
A 'production' version is hosted at nc-news-gjzo.onrender.com. When this example server is not in use it is spun down, so it may take up to a minute for the first request to respond.
I built this as a portfolio project while on the Northcoders JavaScript full-stack course. A seeded database was provided (commit 9d279), after which all code is my own.
- The runtime environment is Node.js
- Testing uses the Jest and Supertest frameworks
- Server functions use Express
- Database functions use PostgreSQL
A list of endpoints is available from /api
Requires PostgreSQL v14.12+ and Node.js v22.3.0+
-
Clone the repo from github.com/stevelw/be-nc-news
git clone https://github.com/stevelw/be-nc-news.git
-
Setup the environment
Create three .env files in the root directory (only
.env.test
is needed to run the tests):.env.test
withPGDATABASE=[YOUR-TEST-DATABASE-NAME]
.env.development
withPGDATABASE=[YOUR-DEVELOPMENT-DATABASE-NAME]
.env.production
withDATABASE_URL=[YOUR-SERVER-URL]
-
Install the development dependencies
cd be-nc-news
npm install -d
-
Setup the database
npm run setup-dbs
There is no need to seed the test database manually.
-
Run tests
npm test
or simplynpm t
If you also wish to run the development environment locally, do the following:
-
Seed the development database
npm run seed
-
Launch the local server
node listen.js
The default port is 9090