How to run nuxt.js in real service?
Asked Answered
B

2

7

I used vue-cli in

vue init nuxt/express myProject

and,

npm run dev

developed.

but,

npm run build

after, was created dist file.

How i can run in real service in pm2?

(I will use ubuntu in AWS EC.)

Bromberg answered 28/5, 2017 at 8:32 Comment(0)
W
13

you just need to start your app like that:

pm2 start npm --name "your-project-name" -- start

Check the status:

pm2 status

and after you can restart / stop:

pm2 restart your-project-name
pm2 stop your-project-name
Whaleboat answered 6/6, 2017 at 23:5 Comment(4)
What is my project name? Nuxt / express Npm Do you need to target the folder created after run build?Bromberg
The project name is just an alias for PM2. The most important is "pm2 start npm -- start", it's the way for PM2 to do a "npm run start", then the "start" script from nuxt know that the target folder is "dist".Whaleboat
I understand now. And I tried. I finally solved it. Thank you very much. Be happy.Bromberg
Add, What folders should be moved during the actual service? Build/main.js and .nuxt/dist?Bromberg
O
1

Prerequisites

  • node.js installed on web server
  • nginx installed and configured on web server
  • pm2 installed and configured on web server

Then

  1. Add to your universal Nuxt app for serving it though PM2 is a file called ecosystem.config.js. Create a new file with that name in your root project directory and add the following content:

     module.exports = {
       apps: [
         {
           name: 'project-name',
           exec_mode: 'cluster',
           instances: 'max', // Or a number of instances
           script: './node_modules/nuxt/bin/nuxt.js',
           args: 'start'
         }
       ]
     }
    
  2. Connect to your linux server via FTP (FileZilla or etc..) Send the blue files I marked to the server. (you don't need to upload node_modues, .nuxt, dist, .git, .idea, etc... folders)

    enter image description here

  3. Connect server via ssh console, (windows : putty) and go to projects folder that you uploaded files.

     cd /
     cd var/www/project-name
    
  4. Install node_modules folder by;

     npm install
    
  5. Execute nuxt build and create .nuxt folder by;

     npm run build
    
  6. Finally, ready to start starts pm2 server by;

     pm2 start
    
Orlov answered 19/5, 2021 at 20:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.