Skip to content

stevelw/be-nc-news

Repository files navigation

Northcoders News - Backend

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

How to run and test locally

Requires PostgreSQL v14.12+ and Node.js v22.3.0+

  1. Clone the repo from github.com/stevelw/be-nc-news

    git clone https://github.com/stevelw/be-nc-news.git

  2. Setup the environment

    Create three .env files in the root directory (only .env.test is needed to run the tests):

    1. .env.test with PGDATABASE=[YOUR-TEST-DATABASE-NAME]
    2. .env.development with PGDATABASE=[YOUR-DEVELOPMENT-DATABASE-NAME]
    3. .env.production with DATABASE_URL=[YOUR-SERVER-URL]
  3. Install the development dependencies

    cd be-nc-news

    npm install -d

  4. Setup the database

    npm run setup-dbs

    There is no need to seed the test database manually.

  5. Run tests

    npm test or simply npm t

If you also wish to run the development environment locally, do the following:

  1. Seed the development database

    npm run seed

  2. Launch the local server

    node listen.js

    The default port is 9090