├── .gitignore ├── ANSWER.md ├── README.md ├── config └── default.json ├── knexfile.js ├── package.json └── server.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | -------------------------------------------------------------------------------- /ANSWER.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/letsface/interview-nodejs/7bc8d3447be4e0781bb9362eb53b5d0ec920d854/ANSWER.md -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NodeJS Interview 2 | 3 | ## Overview 4 | 5 | We want to verify understanding of: 6 | 7 | * built-in Node.JS variables 8 | * proper test structures 9 | * understanding of promises 10 | * use of SQL and schema building 11 | * code hygiene 12 | * exception handling 13 | * usage of npm 14 | * write unit tests 15 | 16 | ## Requirements 17 | 18 | * You MUST use the following libraries: 19 | * Bluebird for Promises, 20 | * **Express.js 4** to build the REST api 21 | * config (http://npmjs.org/package/config) 22 | * **You are not allowed** to use another framework as a base (like Sailjs for instance), or tools that helps build a scaffolding. 23 | * We recommend using: 24 | * knex for database connection (you can use any SQL database, MySQL, PostgreSQL, SQLite, etc) 25 | * Mocha for testing 26 | 27 | ## Instructions 28 | 29 | * Build a database schema, using knex migration (if you are using knex), that follows those requirements: 30 | * An event has a name, a start and end date, 31 | * A user has a username and a password, 32 | * A company has a name, it can have several users and several events 33 | * I should be able to install that database schema on my local machine (hence the use of migration) 34 | 35 | * Design and build a REST API that returns JSON documents in order to: 36 | * create a user, an event, a company 37 | * get a specific event 38 | * list companies, list events 39 | * don't forget to handle errors 40 | 41 | * Don't store the password in clear, you are free to use any strategy to store the password, please detail your choice 42 | in ANSWER.md 43 | 44 | * Write some tests using Mocha, 45 | 46 | * Keep a query log, store it as you like, 47 | 48 | * Describe an authorization system to filter access for creating and getting event. Only users of 49 | a company can create/see event for that company. You are free to use any authorization system you 50 | see fit. **Keep it simple, this is just a test!**. You can check authorization for every query, or authenticate and use session, use API key, whatever you want, the choice is yours! Note 51 | that you are not allowed to use HTTPS. Write your answer in ANSWER.md, any solution is better than no solution! 52 | Explain the advantages (speed of implementation, simplicity of understanding, etc) and the drawbacks. 53 | 54 | ## Tips 55 | 56 | * Don't forget about code re-usability ! 57 | * In knex migrations, each function `up` and `down` MUST return a promise in order to work properly 58 | * Make good use of express middleware 59 | * Use knex seed feature to populate the database for development 60 | * you are free to install any package you think is necessary 61 | * it's ok to ask for help if you're stuck 62 | * Half a solution is better than no solution! 63 | -------------------------------------------------------------------------------- /config/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "database": { 3 | "migrations": { 4 | "tableName": "versions", 5 | "directory": "./migrations/" 6 | }, 7 | "seeds": { 8 | "directory": "./seeds/" 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /knexfile.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var env = 'development' || process.env.NODE_ENV; 4 | var configuration = {}; 5 | 6 | // if the process was passed a environment variable 7 | process.argv.forEach(function(value, index) { 8 | if (value.match(/^--env=/)) { 9 | env = value.split('=')[1]; 10 | } 11 | }); 12 | 13 | process.env.NODE_ENV = env; 14 | 15 | // config require NODE_ENV to be set 16 | var config = require('config'); 17 | configuration[env] = config.get('database'); 18 | 19 | module.exports = configuration; 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "interview", 3 | "version": "1.0.0", 4 | "description": "Interview for NodeJS", 5 | "main": "server.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "node_modules/mocha/bin/mocha test" 11 | }, 12 | "repository": "git@github.com:letsface/interview-nodejs.git", 13 | "author": "sylvain@letsface.com", 14 | "license": "MIT", 15 | "readmeFilename": "README.md", 16 | "dependencies": { 17 | "bluebird": "^2.9.6", 18 | "config": "^1.10.0", 19 | "express": "^4.11.2", 20 | "knex": "^0.7.3" 21 | }, 22 | "devDependencies": { 23 | "mocha": "~1.18.2", 24 | "mocha-jshint": "0.0.7" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var app = express(); 3 | 4 | // PUT YOUR CODE here 5 | 6 | app.listen(3000); --------------------------------------------------------------------------------