World Talking
Search

How to upload a Next.js project on a server

First of all, you need to run a command in your Next.js project: delete the old .next directory and run npm run build

Next Step : ->

  1. After that, the newly created .next directory needs to be converted into a zip file.

  2. After that, you need to copy the server's SSH, open the command prompt, and connect to the server.

Now you need to install npm, Node.js, and PM2 on it. The commands are like this:

Commands : -->

1 . Update your VPS :

  1. sudo apt update

  2. sudo apt upgrade -y

2 . Install Node.js and npm

  1. # Install NodeSource PPA

    curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

  2. # Install Node.js (includes npm)

    sudo apt install -y nodejs

Check installation:

  1. node -v

  2. npm -v

Install PM2 (Process Manager for Node apps)

  1. sudo npm install -g pm2

Check PM2 version:

  1. pm2 -v

After all this, you need to go to your main directory and create a file there.

package.json

And in this file, copy and paste your project's package.json, but make sure to leave out the devDependencies

And now, go back to the CMD and run the npm install command

Notes : Now, in your VPS server's project directory, a node_modules folder will be created.

Now, in the same directory, you need to upload your Next.js build zip file.

And after extracting it, you need to move the .next folder outside into the main project directory.

  • And after that, you need to start the project with pm2 start npm -- start

  • Congratulations, now your website is live. Point your domain and you can check your website.

Category
View All

technology

electronics

ev vehicles

news

history

science

Trending Topic's
technologymobile phonesev carselectronic bikes

© 2025 WWW.WORLDTALKING.COM