Home > Web Front-end > JS Tutorial > body text

How to deploy vue-router and express projects to the server

亚连
Release: 2018-06-05 16:46:12
Original
3011 people have browsed it

Below I will share with you a method of deploying vue-router and express projects to the server. It has a good reference value and I hope it will be helpful to everyone.

- First make sure that this project can run successfully locally

Enter npm run start in the local command line, no error is reported, and open 127.0.0.1:3000

is written The page whose route is /, as shown in the figure

This is the file hierarchy relationship

front is the front-end file

xk3 is the file that links the background express and the database mysql

Use the command line to enter the background and run it. The startup is successful

This is the page with the path /

Enter the path http://localhost:3000/

The browser will display WelCome to express

To this project After running successfully locally, we will now put it on the server.

- Preparation

The basic settings of the previous server will not be described in detail.

Open xftp or other similar software, copy all this project to the /var/www/ path

(This path may be different, it is the path of the server web page)

Import the data required by the background into the server database, the command is mysql>source "path";

Then open xshell and enter the background of this project, similar to To run the background file locally, the premise is that basic configurations such as node and mysql are installed on your server. If you use Baidu yourself, another problem is to make sure that the route in your vue-router obtains the server's ip port router, such as var url = 'http://47.95.7.109:3000/course/batchDelete', and open your 3000 port from Alibaba Cloud's security group configuration, otherwise access will be blocked.

My operation failed because I later used the forever daemon, which has been occupying port 3000, so it cannot be started. If it has not been set up, it can start normally just like in Same as local.

Take the screenshot of my student course selection system as an example

But in this way your server will always be in In the blocking state, as long as the connection is disconnected, the service will also be interrupted.

Create a daemon process

The next step is to use pm2 or forever to create a daemon process. After personal testing, I feel that forever is relatively simple and only requires a few steps. command, no additional configuration is required.

Start using forever

1.sudo npm install forever -g

2.forever start app.js

3.forever start -l forever.log app.js

This is an error I made. There is no error and output log file specified

The error message is: log file /root/.forever/forever.log exists. Use the -a or –append option to append log.

4.Solution

forever start -a -l forever.log -o out.log -e err.log app.js (app.js is the entry file of the background)

If If it still doesn’t work, you can use

forever start -a -l forever.log -o out.log -e err.log ./bin/www

At this time, the node project deployment is completed. Even if the background service of the server is turned off, it can still run normally without blocking.

Pictures of successful operation

If there are any questions, please ask, thank you!

Sample link: http://47.95.7.109/student/work/front/#/

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

What are the steps to input the ngForOf template to the component using content projection through Angular?

What are the process steps for packaging a vue project and publishing it online through Baidu's BAE?

Usage of @HostBinding() and @HostListener() in Angular (detailed tutorial)

The above is the detailed content of How to deploy vue-router and express projects to the server. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!