-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (32 loc) · 1012 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require( 'dotenv' ).config();
const express = require( 'express' );
const mongoose = require( 'mongoose' );
const app = express();
const cors = require( 'cors' );
const port = process.env.PORT || 5000;
const productRoute = require( './routes/productroute' )
// middlewares
app.use( cors );
app.use( express.json() );
app.use( express.urlencoded( { extended: true } ) ); // data can have arrays as well not only strings
// connect to mongodb atlas at
//apis :
app.use( '/api/product', productRoute );
// app.use( function ( req, res, next )
// {
// res.header( "Access-Control-Allow-Origin", '/api/product' );
// res.header( "Access-Control-Allow-Headers" );
// next();
// } )
mongoose.connect( process.env.MONGODB_URL, { useNewUrlParser: true } ).then( () =>
{
console.log( "Connected in the MongoDB Database" )
} ).catch( err =>
{
console.log( "Something wrong happened", err );
} )
// start database
app.listen( port, () =>
{
console.log( `Server started at port ${ port }` )
} )