Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Centos7 builds a node.js project

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Centos7 builds a node.js project. Deployment of basic environment 1. Install node and npmcd / usr/local/src/wget http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz2. Extract the file and install nodetar zxvf node-v0.10.24.tar.gzcd node-v0.10.24./configure-- prefix=/usr/local/node/0.10.24makemake install3. Make a global soft link between the node and npm commands and check whether it is successful. If you output the corresponding version number, the installation is successful!

Ln-s / usr/local/node/0.10.24/bin/node / usr/local/bin/

Ln-s / usr/local/node/0.10.24/bin/npm / usr/local/bin/

two。 Deploy application 1. Initialize the project create a new folder and run npm init to initialize the project mkdir node_project cd node_projectnpm init

During the initial process, there will be an interactive interface for project configuration. Instead of taking screenshots, I will generate a package.json file that contains the details of the project.

two。 The directory structure creates three folders: public, routes, and views. The file structure of the project is as follows

The use of corresponding files and folders: models stores files that operate the database public stores static files, such as css, pictures, etc. Routes stores routing files, views stores template files, index.js program main file package.json stores project information, such as project name, description, author, dependency, etc. Installation depends on installation of the express framework

Npm install express-save

If there is any error reported above, after investigation, it turns out that it is the solution to the problem of ssl:

Npm config set strict-ssl false

Or

Npm config set registry= "http://registry.npmjs.org/"

4. Start the project into the root directory of the project, create an index.js file, and add the following code: cd / usr/local/src/node_projectvim index.jsvar express = require ('express'); var app = express (); app.get (' /', function (res, rep) {rep.send ('Hello, wordword');}); app.listen (3000) then enter it in the console and run index.js in the background

Nohup node index.js &

Check to see if port 3000 is listening

Firewall opens port 3000 to the outside world

The browser can access the ip:3000 port to see the effect.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report