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.testis needed to run the tests):.env.testwithPGDATABASE=[YOUR-TEST-DATABASE-NAME].env.developmentwithPGDATABASE=[YOUR-DEVELOPMENT-DATABASE-NAME].env.productionwithDATABASE_URL=[YOUR-SERVER-URL]
-
Install the development dependencies
cd be-nc-newsnpm install -d -
Setup the database
npm run setup-dbsThere is no need to seed the test database manually.
-
Run tests
npm testor 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.jsThe default port is 9090