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
23 changes: 23 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#Ignore the logs directory
logs/


#Ignoring git and cache folders
.gitignore
.cache

#Ignoring all the markdown and class files
*.md

# redis cache
cache/

# mongo
data/

.env
docker-compose.yml
Dockerfile
src/**/*.spec.ts
src/**/*.test.ts

6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
build
# don't lint nyc coverage output
coverage
25 changes: 25 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.eslint.json"
},
"plugins": ["@typescript-eslint", "prettier", "jest"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:jest/recommended",
"plugin:prettier/recommended"
],
"rules": {
"@typscript-eslint/no-unused-vars": "off",
"@typscript-eslint/no-unused-params": "off",
"no-console": "warn"
},
"env": {
"browser": true,
"node": true,
"jest": true
}
}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,12 @@ dist

# TernJS port file
.tern-port

# tsc output
build/

# redis docker cache
cache/

# redis docker mongo
data/
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 100
}
70 changes: 70 additions & 0 deletions Assesment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Back End Code Challenge

In this Back End Coding Challenge Limbic would like to see your skills and coding habits in a production server environment.

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.

# The Challenge

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

- Register a new user to database
- Create a new post for user in database
- Return user and his posts

## Stack Options:

You can pick from 2 different tech stacks, which are of equal interest to us:

### *PostgreSQL*

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

### *MongoDB*

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

## Requirements:

- It should be production quality as you understand it, i.e. tests, Docker, README, documentation, etc.

## Things we're looking for:

- TypeScript
- Project structure
- Unit tests
- API design
- Error handling
- Dockerize the service

## Bonus!

The following tasks are not required, but will give you an extra bonus if you complete them

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

# Submitting:

### 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)
82 changes: 82 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# FROM node:14-slim

# RUN mkdir -p /usr/src/app

# WORKDIR /usr/src/app

# COPY . .

# RUN npm install

# EXPOSE 8080

# CMD ["node", "/build/app.js"]



ARG PORT=8080

FROM node:14-alpine AS node


# Builder stage

FROM node AS builder

# Use /app as the CWD
WORKDIR /app

# Copy package.json and package-lock.json to /app
COPY package*.json ./

# Install all dependencies
RUN npm i

# Copy the rest of the code
COPY . .

# Invoke the build script to transpile ts code to js
RUN npm run build

# Open desired port
EXPOSE ${PORT}

# Run development server
ENTRYPOINT [ "npm", "run", "start:dev" ]

# Final stage

FROM node AS final

# Set node environment to production
ENV NODE_ENV production

# Update the system
RUN apk --no-cache -U upgrade

# Prepare destination directory and ensure user node owns it
RUN mkdir -p /home/node/app/build && chown -R node:node /home/node/app

# Set CWD
WORKDIR /home/node/app

# Install PM2
RUN npm i -g pm2

# Copy package.json, package-lock.json and process.yml
COPY package*.json process.yml ./

# Switch to user node
USER node

# Install libraries as user node
RUN npm i --only=production

# Copy js files and change ownership to user node
COPY --chown=node:node --from=builder /app/build ./build

# Open desired port
EXPOSE ${PORT}

# Use js files to run the application
ENTRYPOINT ["pm2-runtime", "./process.yml"]
Loading