|
@@ -9,39 +9,24 @@ const User = require('./models/user')
|
|
dotenv.config()
|
|
dotenv.config()
|
|
|
|
|
|
const app = express()
|
|
const app = express()
|
|
-mongoose.connect(process.env.DATABASE,
|
|
|
|
-{ useNewUrlParser: true, useUnifiedTopology: true },
|
|
|
|
-(err) => {
|
|
|
|
- if (err) {
|
|
|
|
- console.log(err)
|
|
|
|
- } else {
|
|
|
|
- console.log('Connected to the database')
|
|
|
|
|
|
+mongoose.connect(
|
|
|
|
+ process.env.DATABASE,
|
|
|
|
+ { useNewUrlParser: true, useUnifiedTopology: true },
|
|
|
|
+ (err) => {
|
|
|
|
+ if (err) {
|
|
|
|
+ console.log(err)
|
|
|
|
+ } else {
|
|
|
|
+ console.log('Connected to the database')
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-})
|
|
|
|
|
|
+)
|
|
|
|
|
|
app.use(morgan('dev'))
|
|
app.use(morgan('dev'))
|
|
app.use(bodyParser.json())
|
|
app.use(bodyParser.json())
|
|
app.use(bodyParser.urlencoded({ extended: false }))
|
|
app.use(bodyParser.urlencoded({ extended: false }))
|
|
|
|
|
|
-app.get('/', (req,res) => {
|
|
|
|
- res.json('hello')
|
|
|
|
-})
|
|
|
|
-
|
|
|
|
-app.post('/', (req,res) => {
|
|
|
|
- let user = new User()
|
|
|
|
- user.name = req.body.name
|
|
|
|
- user.email = req.body.email
|
|
|
|
- user.password = req.body.password
|
|
|
|
-
|
|
|
|
- user.save((err) => {
|
|
|
|
- if (err) {
|
|
|
|
- res.json(err)
|
|
|
|
- } else {
|
|
|
|
- res.json('Successfully saved')
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- // console.log(req.body)
|
|
|
|
-})
|
|
|
|
|
|
+const productRouters = require('./routes/products')
|
|
|
|
+app.use('/api', productRouters)
|
|
|
|
|
|
app.listen(3000, (err) => {
|
|
app.listen(3000, (err) => {
|
|
if (err) {
|
|
if (err) {
|