This commit is contained in:
2018-05-16 18:25:55 +03:00
commit fa053c63d5
9 changed files with 10556 additions and 0 deletions

3
.env.example Normal file
View File

@@ -0,0 +1,3 @@
PORT=4000
MONGODB_URI="mongodb://localhost/todolist"

13
.eslintrc.json Normal file
View File

@@ -0,0 +1,13 @@
{
"extends": ["airbnb-base"],
"rules": {
"linebreak-style": "off",
"no-unused-expressions": [
"error",
{
"allowTernary": true
}
],
"no-console": "off"
}
}

61
.gitignore vendored Normal file
View File

@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# 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
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://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/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# next.js build output
.next

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"editor.tabSize": 2,
"prettier.eslintIntegration": true,
"editor.insertSpaces": true,
}

42
app.js Normal file
View File

@@ -0,0 +1,42 @@
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const methodOverride = require('method-override');
const morgan = require('morgan');
require('dotenv').config();
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(morgan('tiny'));
app.use(methodOverride('_method'));
mongoose.connect(process.env.MONGODB_URI);
require('./models/Todo');
require('./models/TodoList');
// 404 route
app.use((req, res) => {
res.status(404);
if (req.accepts('html')) {
res.send('404');
return;
}
if (req.accepts('json')) {
req.send({ error: 'Not found' });
return;
}
res.type('txt').send('not found');
});
app.listen(process.env.PORT, () => {
console.log('Started!');
});

15
models/Todo.js Normal file
View File

@@ -0,0 +1,15 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;
const todoSchema = Schema({
_id: Schema.Types.ObjectId,
text: {
type: String,
required: true,
},
list: { type: Schema.Types.ObjectId, ref: 'TodoList' },
completed: Boolean,
});
mongoose.model('Todo', todoSchema);

14
models/TodoList.js Normal file
View File

@@ -0,0 +1,14 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;
const todoListSchema = Schema({
_id: Schema.Types.ObjectId,
name: {
type: String,
required: true,
},
todos: [{ type: Schema.Types.ObjectId, ref: 'Todo' }],
});
mongoose.model('TodoList', todoListSchema);

10373
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

30
package.json Normal file
View File

@@ -0,0 +1,30 @@
{
"name": "todolist-nodeback",
"version": "0.1.0",
"private": true,
"description": "",
"main": "app.js",
"scripts": {
"start": "node ./app.js",
"start-mon": "npx nodemon --inspect ./app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"dependencies": {
"body-parser": "^1.18.3",
"dotenv": "^5.0.1",
"express": "^4.16.3",
"https-proxy-agent": "^2.2.1",
"method-override": "^2.3.10",
"mongoose": "^5.1.1",
"morgan": "^1.9.0",
"npm": "^6.0.1"
},
"devDependencies": {
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-config-node": "^2.0.0",
"eslint-plugin-import": "^2.11.0",
"nodemon": "^1.17.4"
}
}