GithubHelp home page GithubHelp logo

node-training's Introduction

Node.js API template

Bootstrapping

  • Read the rest of this README.md
  • Follow the Start project section
  • Run the tests
  • Start the server

After all is setup & running, feel free to remove the local git repository and initialize a new one, rename databases, and remove the sample source code.

Stack

This section is going to show a curated list of the packages and tools used for this project (to see the full list of dependencies take a look at package.json)

Start project

Start project with docker (recommended)

In order to start the project with docker you just need to execute the following script (you should have docker already installed and working on your machine)

./bin/start

The script assumes that you have a .env.sample file that file is going to be copied to a file with the name .env and it's going to be used to start the application

Start project manually

The following files needs to be copied and modified accordingly

$ cp .env.sample .env

After copy those files edit them to have the right values (ask a teammate if you don't know any of those values), then you will need to create the database to do Postres is required to be up and running (if you have it you can avoid the installation instructions for Postgres)

Install tools

PostgreSQL

The easiest way to install postres is using this app, just follow the instructions on their site and you will be ready to go (you might need to reload the terminal to have access to postgres app commands)

Version manager

To install all the tools required by the project you need a tool to manage the version of the tools. Using asdf-vm you can install all the tools, to install it you need to follow the instructions on https://asdf-vm.com/

Node.js

If you want to manage node versions using asdf you need to install a plugin that is able to install the different node versions, to do that just type the following command

$ asdf plugin add nodejs

And then to install nodejs run the following command

$ asdf install nodejs 16.10.0

Install project dependencies

$ yarn install

Create database

Based on the information on the file .env (that you copy previously) create two databases on for test and one for development to do that just run the following command

$ createdb node_template_development
$ createdb node_template_test

Make sure those names matches what you have on .env

Start the project

$ yarn run dev

This command will start a dev server and every change that is made to the code is reflected on the terminal, that is running the code.

By default it will start the server port 3000. If you want to run the server in a different port, update the PORT environment variable

Usage

Migrate and seed database

If you are running the project with docker, first you need to enter to the terminal (inside the container), to do that just type the following command on your shell:

$ ./bin/terminal

Once you are there you can use the following commands to either migrate or seed the database, for none docker users just type the commands directly on the root of the project.

In order to have the latest schema on your database you need to run the following command:

$ yarn migrate:latest

Then to create some seed data for development the following command can be run:

$ npx knex seed:run

Scripts

Code generators

  • To generate an entity scaffold: npx hygen generate scaffold
  • Make migration: npx hygen generate migration
  • Make seed: npx hygen generate seed

Running tests

To run the test just type the following command

$ yarn run test

ESLint & Prettier

To run the linter and fix try to fix issues automatically run the following command

$ yarn run lint -- --fix

Cleanup template files

The template has some example files like models, migrations, and tests for those models once you are comfortable with the template you can execute the following script to clean up the template:

$ ./bin/cleanup

Specific Documentation

node-training's People

Contributors

farchi avatar jjuli93 avatar cdotta avatar elpic avatar dantepotolicchio avatar snmgian avatar b-wils avatar cumanachao avatar jzeni avatar leslyacuna avatar matu1104 avatar mauriciocarbajal avatar pilasguru avatar santiestra avatar

Watchers

 avatar

node-training's Issues

6. Implement first user's endpoint

User's endpoints must check that a valid JWT token comes from the HTTP request.

If JWT token is invalid, user's endpoint should respond with the appropriate response.

A user shouldn't access/modify other users data.

  • Get user's lists

2. Node.js scripting

Write and run simple node.js script

Implement a node.js script that receives a regular expression and prints all of the files that whose filename match the given regular expression under the current directory (recursively)

Example

node fs-scan.js '\.js$'

Output

./node_modules/json-schema/test/tests.js
./node_modules/json-schema/lib/links.js
./node_modules/json-schema/lib/validate.js
./src/lib/tron/redux-tron.js

--
References:

4. Build a node.js tool

Create a tool to list GitHub projects

Implement a node.js tool that given a source GitHub repository, lists the name of the projects and the tasks within those projects.

Format the output in some way that will help a user to see projects and their tasks at a glance.

--
References:

6. Git practice 1

Learn Git Branching provides a good framework for understanding what is really going on when you merge, rebase, etc.

Complete the following sections of the Main challenges (selected via the "Main" tab in the "Select a level" UI):

  • Introduction Sequence
  • Ramping Up
  • Moving Work Around

Then complete the following section of the Remote challenges (selected via the "Remote" tab in the "Select a level" UI):

  • Push & Pull -- Git Remotes!

3. Use a linter

Write code using a consistent style

  • Install eslint, prettier, husky
  • Configure .eslintignore, .eslintrc.js, and .prettierrc.js
  • Configure husky to run the npm run lint on pre-commit
  • Run the linter and fix any warnings and errors

5. Basics about git

Understand how to work with git

Learn about:

  • Different file status life cycles
  • Git remotes
  • Basic commands: add/commit/push

Additional resources:

7. Git workflow

Understand how to use git in a collaborative way and solve common situations faced across a project’s life cycle

Learn about:

  • Feature branches
  • Hotfix branches

5. Add authentication

  • Investigate about JWT
  • Check Authentication section on the template documentation
  • Follow the instructions for configuring everything needed and adding a login endpoint
  • Write a script to add a user and its credentials to the database

2. Design the "moovie" API

Take a look at this diagram (open it with StarUML):

Based on that model, design an API that supports the following operations:

Movies:

  • List movies (supporting paging, filtering, and sorting)
  • Get movie

Lists:

  • Get user lists
  • Create list
  • Get list
  • Update list
  • Delete list
  • Add movie to list
  • Remove movie from list

Genres:

  • Get genres

User profile:

  • Get user profile
  • Update user profile
  • Upload user photo
  • Remove user photo

For each one of the above operations, you should specify:

  • HTTP method
  • HTTP path
  • path parameters
  • query parameters parameters
  • Possible HTTP response codes
  • Success response schema
  • Error response schema

NOTE: Don't design for authentication / authorization in mind. These topics will be covered later.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.