Create a node. js static server with Http-server

Source: Internet
Author: User

Today do a book on the example, the result code does not work, query, is the syntax is outdated, the book is actually new bought, published soon.

The outdated code is as follows

var connect=require (' Connect '); Connect.createserver (     connect.static (". /angularjs ")). Listen (5000);

Error hint: Connect.static is not a method

Since my goal is to practice angularjs, not to learn nodejs, so do not go into the drill, as long as you can build a simple server on the line

The search method on the Internet is to create a node. js static server with Http-server

1. Global Installation Http-server

NPM install-g Http-server

2.http-server start

Http-server-a 127.0.0.1-p 5000

"

One of the commands above starts a node. js static server. Listen for local 7070 ports.

The static directory is the directory where the command is currently running

If the public folder exists in your current project, the default static directory is assigned to public
If there is no public folder, then the static directory is the root directory.

"

This passage is a reference to a http://yijiebuyi.com/blog/b0f6ddc56be457e13879a3ad105f561b.html on a commoner's blog.

The environment referred to should be Linux

You can write http-server-a 127.0.0.1-p 7070 to the Scripts node in the Package.json file


"Scripts": {
"Start": "Http-server-a 127.0.0.1-p 7070"
}

This allows you to start a static server with NPM start

Create a node. js static server with Http-server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.