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

Setting up NodeJs server under Windows environment

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly explains "Building NodeJs Server in Windows Environment". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's take you to learn "Building NodeJs Server in Windows Environment"!

preface

Nodejs is a JavaScript scripting language for Google V 8 engine, which is actually equivalent to a server that can parse web content and produce effects. It makes JavaScript even more powerful, and Node executes faster than JavaScript and supports distribution because it uses an event-driven, non-blocking model. It's boring to talk too much. Let's build one ourselves.

Download Nodejs

Since Xiaobian is a Win7 system, the new Nodejs does not support it, I don't know why. It is friendly to Win8. So Xiaobian downloaded it from Tsinghua Mirror and shared it with everyone. There are two versions here, one is the installation package version (suffix is.msi) without configuring environment variables; the other is the compressed package, directly decompress and then configure environment variables. Here Xiaobian suggests that you download the installation package, considering that some people do not understand how to set environmental variables, or install the package better, Xiaobian steal a lazy install package.

Install Nodejs

First we need to agree to its user agreement, and then choose the installation path, there is no hard and fast rule must be placed on the system disk, then please put it on other disks, as follows:

Then click Next, you will see the environment settings and installation dependencies, regardless, Next continues, as follows:

Then we will see that there is an option, as shown in the figure:

This is to let us choose this tool, select it will download, it is recommended to choose, and then wait a moment, the installation will be ready immediately, as shown in the figure:

At this time, a CMD window will appear, prompting us to download tools, and we need to close all windows, as shown in the figure:

After pressing Enter, complete the flash back, enter CMD, enter the command to obtain the Node version number, if it returns, it means that the installation is successful, as follows:

III. New Projects

First create a folder, name does not use Chinese and capital letters, and then we open the command prompt in this directory, and enter the command "npm init," as follows:

Here we press Enter step by step, and finally enter Yes to create a Node project. All of the above are project configurations. Open the folder to see, as shown in the figure:

A file in Json format is created. Then we need to create a static repository for this project, generally put pictures, HTML something, named Static, and then put an HTML file in, named "index.html", as for the content to write casually; then we need to create a Json file in the Json file directory, used to start the server, first write a random, as shown in the figure:

Then we access it. At this time, this JS file is the server-side program, and the access will produce the result, as shown in Figure:

Create a server that can be accessed in a browser

The above we have established can only be accessed in Node, not in the browser, the following establishment of a browser can be accessed, this is called the server? Let's start by creating a Js file for the server that reads as follows:

var http = require('http'); var server = http.createServer(function (req,res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }); server.listen(8080,'127.0.0.1'); console.log('Server running on http://127.0.0.1:8080/');

Then we start the service in CMD as follows:

Success.

At this point, I believe that everyone has a deeper understanding of "building NodeJs server in Windows environment", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

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