File tree 10 files changed +92
-27
lines changed
10 files changed +92
-27
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "presets" : [" es2015" , " stage-2" ]
3
+ }
Original file line number Diff line number Diff line change 1
1
.idea
2
+ .env
2
3
node_modules /
4
+ dist /
3
5
package-lock.json
Original file line number Diff line number Diff line change
1
+ require('babel-register');
2
+ require('dotenv/config');
3
+ require('../src/server');
Original file line number Diff line number Diff line change
1
+ require('../dist/server');
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " todo-api" ,
3
3
"version" : " 1.0.0" ,
4
- "description" : " " ,
4
+ "description" : " my first node api " ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
7
- "test" : " echo \" Error: no test specified\" && exit 1"
7
+ "test" : " echo \" Error: no test specified\" && exit 1" ,
8
+ "start" : " node bin/dev" ,
9
+ "clean" : " rm -rf dist" ,
10
+ "build" : " npm run clean && mkdir dist && babel src -s -d dist" ,
11
+ "production" : " npm run build && node bin/production"
8
12
},
9
13
"author" : " " ,
10
14
"license" : " ISC" ,
11
15
"dependencies" : {
12
- "mongodb" : " ^3.0.7"
16
+ "body-parser" : " ^1.18.2" ,
17
+ "express" : " ^4.16.3" ,
18
+ "mongodb" : " ^3.0.7" ,
19
+ "mongoose" : " ^5.0.16"
20
+ },
21
+ "devDependencies" : {
22
+ "babel-cli" : " ^6.26.0" ,
23
+ "babel-preset-es2015" : " ^6.24.1" ,
24
+ "babel-preset-stage-2" : " ^6.24.1" ,
25
+ "babel-register" : " ^6.26.0" ,
26
+ "dotenv" : " ^5.0.1"
13
27
}
14
28
}
Original file line number Diff line number Diff line change
1
+ let mongoose = require ( 'mongoose' ) ;
2
+
3
+ mongoose . Promise = global . Promise ;
4
+ mongoose . connect ( 'mongodb://localhost:27018/TodoApp' ) ;
5
+
6
+ export default mongoose ;
Original file line number Diff line number Diff line change
1
+
2
+ import mongoose from 'mongoose' ;
3
+
4
+ const Todo = mongoose . model ( 'Todo' , {
5
+ text : {
6
+ type : String ,
7
+ required : true ,
8
+ minLength : 1 ,
9
+ trim : true
10
+ } ,
11
+ isCompleted : {
12
+ type : Boolean ,
13
+ default : false
14
+ } ,
15
+ completedAt : {
16
+ type : Number ,
17
+ default : null
18
+ }
19
+ } ) ;
20
+
21
+ export default Todo ;
Original file line number Diff line number Diff line change
1
+
2
+ import mongoose from 'mongoose' ;
3
+
4
+ const User = mongoose . model ( 'User' , {
5
+ email : {
6
+ type : String ,
7
+ required : true ,
8
+ minLength : 1 ,
9
+ trim : true
10
+ }
11
+ } ) ;
12
+
13
+ export default User ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import express from 'express' ;
2
+ import mongoose from './db/mongoose' ;
3
+
4
+ import bodyParser from 'body-parser' ;
5
+
6
+ import User from './models/user' ;
7
+ import Todo from './models/todo' ;
8
+
9
+ // console.log(global);
10
+ // console.log(process);
11
+ // console.log(module);
12
+ console . log ( process . env . SEC ) ;
13
+
14
+ let app = express ( ) ;
15
+
16
+ app . use ( bodyParser . json ( ) ) ;
17
+
18
+ app . post ( '/todos' , ( req , res ) => {
19
+ console . log ( req . body ) ;
20
+ } ) ;
21
+
22
+ app . listen ( 3001 , ( ) => {
23
+ console . log ( 'Started on port 3001' ) ;
24
+ } ) ;
25
+
26
+
You can’t perform that action at this time.
0 commit comments