如何使用“EXPRESS”实现后端和使用“NUXT.JS”实现前端

时间:2021-04-01 06:02:25

标签: javascript node.js mongodb express nuxtjs

我是网络开发新手,对这个问题表示抱歉。事情是我已经用Express做了一个服务器端并连接到MongoDB,已经建立了我可以插入,选择,删除信息的连接,但不知道如何用NUXT.JS制作前端,我想把前端有 4 个按钮,分别是选择、插入、删除按钮。这是我的后端:

const express = require('express');
const bodyParser = require('body-parser');

// create express app
const app = express();

// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }))

// parse requests of content-type - application/json
app.use(bodyParser.json())

// Configuring the database
const dbConfig = require('./config/database.config.js');
const mongoose = require('mongoose');

mongoose.Promise = global.Promise;

// Connecting to the database
mongoose.connect(dbConfig.url, {
    useNewUrlParser: true
}).then(() => {
    console.log("Successfully connected to the database");    
}).catch(err => {
    console.log('Could not connect to the database. Exiting now...', err);
    process.exit();
}); 
// define a simple route
app.get('/', (req, res) => {
    res.json({"message": "Welcome to EasyNotes application. Take notes quickly. Organize and keep track of all your notes."});
});

// Require Notes routes
require('./app/routes/note.routes.js')(app);
// listen for requests
app.listen(3000, () => {
    console.log("Server is listening on port 3000");
});     

0 个答案:

没有答案