Building a web application using the Nuxt.js framework and Express generator

Seeking help to seamlessly integrate an express app generated with express generator into my nuxt.js application.

Came across this https://github.com/nuxt-community/express-template, although it seems to only cover basic express applications.

Any recommendations for a comprehensive tutorial on integrating an express application (generated with express generator) with nuxt.js?

Answer №1

Lately, I incorporated NUXT into my Express.js Application and wanted to share my setup example.

https://github.com/iampaul83/express-nuxt

Implementing NUXT.js with Express.js

1. Setting up express generator and installing nuxt

# express generator
npx express-generator --pug --git express-nuxt
cd express-nuxt
yarn

# nuxt
yarn add nuxt @nuxtjs/axios
yarn add --dev eslint babel-eslint eslint-friendly-formatter eslint-loader eslint-plugin-vue

2. Adding the nuxt folders

  • nuxt
    • assets
    • components
    • layouts
    • middleware
    • pages
    • plugins
    • static
    • store

3. Creating nuxt.config.js file

The srcDir option is crucial if you plan to locate nuxt in a sub folder

module.exports = {
  mode: 'universal',

  srcDir: __dirname,
  /*
  ** Headers of the page
  */
  head: {
    title: 'nuxt',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: 'Nuxt.js project' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  /*
  ** Customize the progress bar color
  */
  loading: { color: '#3B8070' },

  modules: [
    // Doc: https://github.com/nuxt-community/axios-module#usage
    '@nuxtjs/axios'
  ],

  /*
  ** Axios module configuration
  */
  axios: {
    // See https://github.com/nuxt-community/axios-module#options
  },

  /*
  ** Build configuration
  */
  build: {
    /*
    ** Run ESLint on save
    */
    extend (config, { isDev, isClient }) {
      if (isDev && isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
    }
  }
}

4. Creating nuxt-render.js for rendering

const { Nuxt, Builder } = require('nuxt')

const config = require('./nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')

const nuxt = new Nuxt(config)

// build nuxt
if (config.dev) {
    const builder = new Builder(nuxt)
    builder.build().catch((error) => {
        console.log('failed to build nuxt')
        console.log(error)
    })
}

module.exports = nuxt.render

5. Adding nuxt render middleware in app.js

app.use(require('./nuxt/nuxt-render'));

6. Including .eslintrc.js file

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true
  },
  parserOptions: {
    parser: 'babel-eslint'
  },
  extends: [
    // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
    // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
    'plugin:vue/essential',
  ],
  // required to lint *.vue files
  plugins: [
    'vue'
  ],
  // add your custom rules here
  rules: {}
}

7. Adding .gitignore for nuxt

# Nuxt build
.nuxt

# Nuxt generate
dist

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with executing Athena query using athena-express when using req.body as input

Seeking guidance on querying specific data from AWS Athena using req.body parameters. When attempting to execute the query with req.body in postman, encountering the following error: Error: SYNTAX_ERROR: line 1:1: Incorrect number of parameters: expected 1 ...

What is the process for obtaining documents that contain arrays with duplicate elements in them?

Looking at my MongoDB documents below, I have identified a pattern: { _id: ObjectId('09de14821345dda65c471c99'), items: [ _id: ObjectId('34de64871345dfa655471c99'), _id: ObjectId('34de64871345dfa655471c91&apo ...

Error: Missing authorization header on certain requests for Axios in iOS devices

I have a vuejs application where I am utilizing axios for handling HTTP requests. The authorization header is being set through a request interceptor, like this: const api = axios.create({ baseURL: process.env.API_URL, crossdomain: true, headers: { ...

Storing JSON data using Vuex

As I am delving into the world of Vuex store used with vue.js, I find myself wanting to implement it in a specific scenario. 1. Is STATE referring to any data, whether static or dynamic, that is provided by the server or stored in a JSON format? TEMPLATE ...

Retrieving a file from FormData using ExpressJS

I am new to utilizing ExpressJS for file uploads and sending data through AJAX post as FormData object. I have successfully posted from the front end, but I am having trouble retrieving the data on the server side. Here is the code snippet that I have att ...

Concealing a VueJs component on specific pages

How can I hide certain components (AppBar & NavigationDrawer) on specific routes in my App.vue, such as /login? I tried including the following code in my NavigationDrawer.vue file, but it disables the component on all routes: <v-navigation-drawer ...

Managing dependencies with Yarn or npm

While experimenting with remix and mui v5, I encountered some issues. When using npm and running npm run dev, I received the following error: Error: Directory import '.../playground/remix-mui-dev/node_modules/@mui/material/styles' is not supporte ...

The 'default' property in Topojson is currently not defined

I've been grappling with this issue for the past hour to no avail. My current task involves working with d3-world-maps, which has a dependency on topojson. The problem seems to be stemming from within the d3-world-maps package: var _topojson = requi ...

NodeJS - leveraging forked processes on a single virtual machine with multiple processors versus the utilization of multiple virtual machines running a single process

In my NodeJS development project, I am working on a service that generates text files from images using a node wrapper for the tesseract OCR engine. The goal is to have this service running continuously, starting and restarting (in case of a crash) using u ...

I'm facing a challenge where Multer is preventing me from showing images in my React app

Hi there, I'm currently facing an issue where I am using multer to save files on my server and store their path in mongodb. However, I am struggling to display them on my React application. Any assistance would be greatly appreciated. Thank you in ad ...

Bringing custom JavaScript functions into a Vue.js component

In my Vue.js project, I have an abundance of Javascript processing that is all local and doesn't require server-side functionality. I'm exploring the possibility of importing a file containing specific processing functions (such as mathematical a ...

Executing TestCafe by Initiating Test through POST Request in Express

I've been struggling with a question that I can't seem to find the answer to. Within my Express.js API, I am running tests where I have set up a page with a button and a field for entering a keyword to be used in a TestCafe test. The endpoint I& ...

Can you use curly brackets variables within a v-for loop in Vue.js?

In the dataset that I have items: [ { name: "Breakfast", comp: "breakfastItems" }, { name: "Lunch", comp: "lunchItems" }, { name: "Dinner", comp: "dinnerItems" }, { name: "Dessert", comp: "desertItems" } ] The comp p ...

Attempting to fetch package from an unconventional repository via npm install

When I work on my Node project at the office on a Mac, everything runs smoothly. However, when I try to work on it from home on a Windows machine, I encounter an access rights error while attempting to run npm install. Within my package.json, I have liste ...

Jest identifies an open handle when working with an Express application

For quite some time now, I've been grappling with a particular issue. It all started when I was conducting basic integration tests using a MongoDB database. However, I've minimized the code to its simplest form. The only thing left running is a s ...

Setting up a CentOs Linux environment to host and run a node.js server

Just installed node.js on my new VPS server. I have written a basic script called "server.js" and it is currently running on port 8080. The location of the script is in the "var/www/html/" directory. However, whenever I try to access my domain, it only dis ...

The cPanel Node.js application is experiencing difficulties connecting to the MongoDB Atlas cluster, yet it functions without any issues on

Having developed a website using Node.js with MongoDB Atlas as the database, I encountered no issues while testing it on Heroku. However, after purchasing my domain and switching to proper hosting, I faced challenges. I attempted to set up my website by c ...

Implementing single sign-on across different domains with an express server, react client, and redirect functionality

To tackle the challenge at hand, I am working on developing a web application that involves a form submission to my express server. The process includes generating a token from an external endpoint post using the form value, utilizing this token from an ex ...

Facing Issues with HTTP Headers in Express or Node?

I have developed an Express/NodeJS REST API that includes setting a custom header on the response: router.route("/api/articles") .get(authCheck, function (req, res) { let pagination = req.get('Pagination').split(","); let cur ...

Is the utilization of sockets by Electron's ipcMain/ipcRenderer a common practice?

Scenario In my unique Electron application that is securely isolated and void of node integration, I am faced with the challenge of transferring image data from the renderer to the main process. A notable discussion on this particular thread suggests tha ...