zoukankan      html  css  js  c++  java
  • 使用http-server开启一个本地服务器

    前言

    在写前端页面中,经常会在浏览器运行HTML页面,从本地文件夹中直接打开的一般都是file协议,当代码中存在httphttps的链接时,HTML页面就无法正常打开,为了解决这种情况,需要在在本地开启一个本地的服务器。
    本文是利用node.js中的http-server,开启本地服务,步骤如下:

    1 下载node.js

    官网地址: https://nodejs.org
    下载完成后在命令行输入命令$ node -v以及$ npm -v检查版本,确认是否安装成功。

    2 下载http-server

    在终端输入:

    $ npm install http-server -g

    3 开启 http-server服务

    终端进入目标文件夹,然后在终端输入:

    $ http-server -c-1   (⚠️只输入http-server的话,更新了代码后,页面不会同步更新)
    Starting up http-server, serving ./
    Available on:
      http://127.0.0.1:8080
      http://192.168.8.196:8080
    Hit CTRL-C to stop the server

    也可以执行:

    http-server -a 127.0.0.1 -p 8080 -c-1

    这样就可以同步更新页面并且设置了ip和端口号

    4 关闭 http-server服务

    按快捷键CTRL-C
    终端显示^Chttp-server stopped.即关闭服务成功。

    摘自:https://www.cnblogs.com/nolaaaaa/p/9126385.html

  • 相关阅读:
    121. Best Time to Buy and Sell Stock
    玩转算法2.3常见的算法复杂度分析
    数组中的逆序对
    一些基本的代码模板
    230. Kth Smallest Element in a BST
    42. Trapping Rain Water
    api token
    仿百度查询
    baidu jsonp
    How to fix Error: laravel.log could not be opened?
  • 原文地址:https://www.cnblogs.com/hjbky/p/14421960.html
Copyright © 2011-2022 走看看