Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
dist
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DATABASE_CLIENT=postgres
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USERNAME=admin
DATABASE_PASSWORD=admin
DATABASE_NAME=postgres
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
123 changes: 27 additions & 96 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,104 +1,35 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
66 changes: 66 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
###################
# BUILD FOR LOCAL DEVELOPMENT
###################

FROM node:18-alpine As development

# Create app directory
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available).
# Copying this first prevents re-running npm install on every code change.
COPY --chown=node:node package*.json ./

# Install app dependencies using the `npm ci` command instead of `npm install`
RUN npm ci

# Bundle app source
COPY --chown=node:node . .

# Use the node user from the image (instead of the root user)
USER node

###################
# BUILD FOR PRODUCTION
###################

FROM node:18-alpine As build

WORKDIR /usr/src/app

COPY --chown=node:node package*.json ./

# In order to run `npm run build` we need access to the Nest CLI.
# The Nest CLI is a dev dependency,
# In the previous development stage we ran `npm ci` which installed all dependencies.
# So we can copy over the node_modules directory from the development image into this build image.
COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules

COPY --chown=node:node . .

# Run the build command which creates the production bundle
RUN npm run build

# Set NODE_ENV environment variable
ENV NODE_ENV production

# Running `npm ci` removes the existing node_modules directory.
# Passing in --only=production ensures that only the production dependencies are installed.
# This ensures that the node_modules directory is as optimized as possible.
RUN npm ci --only=production && npm cache clean --force

USER node

###################
# PRODUCTION
###################

FROM node:18-alpine As production

# Copy the bundled code from the build stage to the production image
COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules
COPY --chown=node:node --from=build /usr/src/app/dist ./dist

# Start the server using the production build
CMD [ "node", "dist/main.js" ]
100 changes: 53 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,76 @@
# Back End Code Challenge
## Local Infrastructure

In this Back End Coding Challenge Limbic would like to see your skills and coding habits in a production server environment.
Use **docker-compose** to run infrastructure locally.

Please don't spend more than about 8 hours on this. We are mostly interested in seeing your coding style and patterns, even if you don't finish everything.
Launch the containers in detached mode.

# The Challenge
```shell
docker-compose -p="backend-code-challenge" up -d
```

You are tasked with writing an API to create Users and Posts. It should be a Node.js server with the following endpoints:
Stop the running containers.

- Register a new user to database
- Create a new post for user in database
- Return user and his posts
```shell
docker-compose -p backend-code-challenge down
```

## Stack Options:
## Containers
- Postgres
- Server available on `localhost:5432`
- Log in with `admin / admin`
- Database name is `services`
- pgAdmin
- UI available on http://localhost:8080
- Log in with `[email protected] / admin`
### Description

You can pick from 2 different tech stacks, which are of equal interest to us:
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

### *PostgreSQL*
### Installation

- TypeScript
- Node.js
- Apollo GraphQL
- PostgreSQL (you may use an ORM like Sequelize if you like)
- Jest / Mocha-Chai
```bash
$ npm i
```

### *MongoDB*

- TypeScript
- Node.js
- Express
- MongoDB (you may use libs other than the native one if you like)
- Jest / Mocha-Chai
### Migration

## Requirements:
Use the migration:generate command to let TypeORM generate the migration file.

- It should be production quality as you understand it, i.e. tests, Docker, README, documentation, etc.
```bash
$ npm run typeorm:generate-migration --name=MigName
```

## Things we're looking for:
To run migrations
```
$ npm run typeorm:run-migrations
```
### Running the app

- TypeScript
- Project structure
- Unit tests
- API design
- Error handling
- Dockerize the service
```bash
# development
$ npm start

## Bonus!
# watch mode
$ npm start:dev

The following tasks are not required, but will give you an extra bonus if you complete them
# production mode
$ npm run start:prod
```

- Update user, taking into consideration possible concurrency issues
- Integration tests
### Test

# Submitting:
```bash
# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
```

### Option A:

- Fork this repo
- Issue a Pull Request when you're ready to start. This will count as your starting date
- Set up your development environment chosen
- Implement your server
- Commit changes into the forked repo

### Option B:

- Setup your development environment chosen
- Implement your server
- Archive your solution into a zip file
- Send us the zip file. We should be able to extract the content and run it from there (w/o node_modules)
Loading