P
P
picka2021-03-22 22:44:42
Express.js
picka, 2021-03-22 22:44:42

How to deploy an Express.js application in conjunction with Nuxt.js on Beget hosting?

I have a Node.js application on Express.js and Nuxt.js. The first is responsible for the server and API, the second for the frontend.

Problem : everything works fine on the locale, but when running on the Beget server via SSH connection, when the terminal window is closed, Express is disconnected, and only Nuxt remains.

Most likely I'm not launching the application itself. I was previously advised by support to start a clean Nuxt.js project using the 'nuxt-start' package. Everything worked! But now I still have Express connected and I have no idea how to run it.

Here is my server startup code:

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

// Создание express
const app = express()

// Импорт Nuxt.js
const config = require('../nuxt.config.js')
config.dev = process.env.NODE_ENV !== 'production'

async function start () {
    // Инициализация Nuxt.js
    const nuxt = new Nuxt(config)

    const { host, port } = nuxt.options.server

    // Сборка в режиме разработчика
    if (config.dev) {
        const builder = new Builder(nuxt)
        await builder.build()
    } else {
        await nuxt.ready()
    }

    // Запуск Nuxt.js через Express
    app.use(nuxt.render)

    // Прослушка сервера
    app.listen(port, host)
}

start()


Maybe someone has already faced the task of running Express on Beget?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Talalaev, 2021-03-22
@picka

You have written few details. But as I understand you have vps and you log in via ssh and just run in the console node app.js?
For good, you need to do a normal cycle with ci / cd.
In any case, start with pm2 .
And then there will be pm2 start app.js.
pm2 will take control of the process for the application.
When deploying, you need to restart it (I repeat for good, you need ci / cd scripts, etc.).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question