Skip to content

JonDotsoy/HN-Feed-Node.js

Repository files navigation

HN Feed (Node.js)

What is this? I love the hacker news and love NodeJS, If you like it too, you should download it. This is a news panel with auto refresh written in Node JS with Babel 7. See more down to learn how to run it. Good luck 😁.

— Jonathan


Code in practice with Express + Mongo DB.

Preview

🔴 LIVE PREVIEW ON HERE hn.jon.soy.

Dependencies

The requirement of software:

  • Node greater than 8.9.0
  • MongoDB (Prefer greater than 3.4.10)

Optional:

How to install

⚠ Go to the project folder.

Use the next command line

$ npm install

Do you use Docker?

Use docker-compose to up mongo service

# Up the services required
$ docker-compose up -d
# Use without "-d" to view the logs
$ docker-compose up

Up the MongoDB

Please read the next article to run MongoDB.

How to configure this app

Use the .env file to define the configurations.

All configurations are used with the environment variables.

Environment Variable Default Description
DB_HOST 'localhost' Host to connect with MongoDB
DB_POST '27017' Port to connect with MongoDB
DB_NAME 'practice' Name of the collection to use
DB_PASSWORD void Password to connect with MongoDB
DB_USERNAME void Username to connect with MongoDB
HOST '::' Host of the server
PORT '3000' Port of the server

Also, you can use the set to define the configuration in your environment. For example.

# set the port to open server
$ set PORT=9000

How to run APP

To run the APP use then next command line.

$ npm start

This command loads the src/index.js file. This file is transpiled with Babel@7 (See .babelrc.js to read the spec).

App structure

  • src/index.js: This file initializes the connection with mongo and loads the modules.
  • src/modules: Save the modules (A module is a code snippet to work in a process, Ej. render the home.).
  • src/schemas: Save the schemas (A schema define the model to use in the db.)
  • src/schemas/Article.js: Define the schema to use the Article Model.
  • src/resources
  • src/resources/views: Save the views written on Pug files.
  • src/resources/views/articles.pug: Render an article collection.
  • src/resources/views/layout.pug: Define the layout base to any renders on here has the head tag and body tag.

Alternative to install more easy

This instruction use Docker to run the project.

Please install Docker and docker-compose (docker-compose is included in the default docker installation)

Well, If do you have Docker installed, Run the next command line.

# Load docker-compose with `docker-compose.prod.yml` file
$ docker-compose -f docker-compose.prod.yml up -d
# Starting hn-feed-practice-express-mongo-db ...
# Starting hn-feed-practice-express-mongo-db ... done
# Starting hn-feed-practice-express-mongo-app ...
# Starting hn-feed-practice-express-mongo-app ... done

This builds the project and runs under Node. Also, this prepared the MongoDB.

About

This is a practice project, with education motive

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published