Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- //customer.js
- //
- let mongoose = require('mongoose');
- // Article Schema
- let custSchema = mongoose.Schema({
- name:{
- type: String,
- required: true
- },
- surname:{
- type: String,
- required: true
- },
- birthday:{
- type: String,
- required: true
- },
- deathday:{
- type: String,
- required: true
- },
- gender:{
- type: String,
- required: true
- }
- });
- let Customer = module.exports = mongoose.model('Customer', custSchema);
- //
- //app.js
- //
- const express = require('express');
- const path = require('path');
- const mongoose = require('mongoose');
- const bodyParser = require('body-parser')
- mongoose.connect('mongodb://localhost:27017/artontw', { useNewUrlParser: true, useUnifiedTopology: true});
- let db = mongoose.connection;
- // Check connection
- db.once('open', function(){
- console.log('Connected to MongoDB')
- });
- // Check DB errors
- db.on('error', function(err){
- console.log(err);
- });
- // Init App
- const app = express();
- // Load View Engine
- app.set('views', path.join(__dirname, 'views'));
- app.set('view engine', 'pug');
- // parse application/x-www-form-urlencoded
- app.use(bodyParser.urlencoded({ extended: false }));
- // parse application/json
- app.use(bodyParser.json());
- // Set public folder
- app.use(express.static(path.join(__dirname, 'public')));
- // Route files
- let router = require('./router.js');
- app.use('/', router);
- // Start Server
- app.listen(7000, function(){
- console.log('Server started on 7000');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement