mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-28 23:57:49 +01:00
init
This commit is contained in:
3
.env.example
Normal file
3
.env.example
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
PORT=4000
|
||||||
|
|
||||||
|
MONGODB_URI="mongodb://localhost/todolist"
|
||||||
13
.eslintrc.json
Normal file
13
.eslintrc.json
Normal 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
61
.gitignore
vendored
Normal 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
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"editor.tabSize": 2,
|
||||||
|
"prettier.eslintIntegration": true,
|
||||||
|
"editor.insertSpaces": true,
|
||||||
|
}
|
||||||
42
app.js
Normal file
42
app.js
Normal 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
15
models/Todo.js
Normal 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
14
models/TodoList.js
Normal 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
10373
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
package.json
Normal file
30
package.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user