It is the start of a New Year and you have decided to try Visual Studio Code, good resolution!

One of the things you will find the most surprising, is that unlike its big brother Visual Studio which has IIS Express, VS Code does not come with a built-in web server…

If you are building a client side SPA, such as an Angular app, it is crucial to develop and test in the context of a web server (http://localhost:xxx/…).

So nothing built-in so far, but no worries, there are at least 1 thousand way to setup a local web server.

I chose to use the following procedure, which is quite simple yet powerful. What works for me might not suit your need, your mileage might vary.

Please note: this is for your Development Environment only, not Production!

The following procedure is valid for MAC or PC.

1. Install Node.js

If not already installed, get it here: https://docs.npmjs.com/getting-started/installing-node

It comes with npm (the package manager for acquiring and managing your development libraries)

2. Create a new folder for your project

Somewhere in your drive, create a new folder for your web app.

3. Add a package.json file to the project folder

Then copy/paste the following text:

{
   “name”: “Demo”,
   “version”: “1.0.0”,
   “description”: “demo project.”,
   “scripts”: {
     “lite”: “lite-server –port 10001”,
     “start”: “npm run lite”
   },
   “author”: “”,
   “license”: “ISC”,
   “devDependencies”: {
     “lite-server”: “^1.3.1”
   }
}

4. Install the web server

In a terminal window (command prompt in Windows) opened on your project folder, run this command:

npm install

This will install lite-server (defined in package.json), a static server that loads index.html in your default browser and auto refreshes it when application files change.

5. Start the local web server!

(Assuming you have an index.html file in your project folder).

In the same terminal window (command prompt in Windows) run this command:

npm start

Wait a second and index.html is loaded and displayed in your default browser served by your local web server!

lite-server is watching your files and refreshes the page as soon as you make changes to any html, js or css files.

And if you have VS Code configured to auto save (menu File / Auto Save), you see changes in the browser as you type!

Notes:

  • Do not close the command line prompt until you’re done coding in your app for the day
  • It opens on http://localhost:10001 but you can change the port by editing the package.json file.

That’s it. Now before any coding session just type npm start and you are good to go!

Visual Studio Code and local web server的更多相关文章

  1. Web Servers in Visual Studio for ASP.NET Web Projects

    https://msdn.microsoft.com/en-us/library/58wxa9w5(v=vs.120).aspx When you develop web projects in Vi ...

  2. 对于Web开发最棒的22个Visual Studio Code插件

    翻译    原文作者:James Quick    原文地址:https://scotch.io/bar-talk/22-best-visual-studio-code-extensions-for- ...

  3. Project Perfect让Swift在server端跑起来-Perfect in Visual Studio Code (四)

    编者语 : 本系列文章已经被Perfect官方引用了,这样的感觉非常好.感恩!Thx all ! Visual Studio Code是一个轻量级的编辑器,但也功能丰富,通过插件你能够完毕如Cordo ...

  4. 如何使用Visual Studio Code调试PHP CLI应用和Web应用

    在按照Jerry的公众号文章 什么?在SAP中国研究院里还需要会PHP开发? 进行XDebug在本地的配置之后,如果想使用Visual Studio Code而不是Eclipse来调试PHP应用,步骤 ...

  5. React调试——visual studio code

    原文链接:Using React in Visual Studio Code 原文链接:Live edit and debug your React apps directly from VS Cod ...

  6. Version Controlling with Git in Visual Studio Code and Azure DevOps

    Overview Azure DevOps supports two types of version control, Git and Team Foundation Version Control ...

  7. [一]Cesium利其器——Visual Studio Code

    Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ IDE Web前端刚入门的朋友,常常想选择一个快速.好用.流行( ...

  8. docker4dotnet #3 在macOS上使用Visual Studio Code和Docker开发asp.net core和mysql应用

    .net猿遇到了小鲸鱼,觉得越来越兴奋.本来.net猿只是在透过家里那田子窗看外面的世界,但是看着海峡对岸的苹果园越来越茂盛,实在不想再去做一只宅猿了.于是,.net猿决定搭上小鲸鱼的渡轮到苹果园去看 ...

  9. ASP.NET Core 中文文档 第二章 指南(1)用 Visual Studio Code 在 macOS 上创建首个 ASP.NET Core 应用程序

    原文:Your First ASP.NET Core Application on a Mac Using Visual Studio Code 作者:Daniel Roth.Steve Smith ...

随机推荐

  1. Epson 微型打印机打印 LOGO C#

    由于项目需要使用EPSON微型打印机打印LOGO,在网上查看了很多都是安装驱动然后设置打印机图片. 项目需要使用Bytes发送流,最后在网上找到了一些资料,记录下来方便自己和其他人使用. public ...

  2. findbugs插件使用

    本文以idea的插件举例子 介绍 Findbugs是一个静态分析工具,它检查类或者JAR 文件,将字节码与一组缺陷模式进行对比以发现可能的问题. idea安装 自此,插件安装完毕,需要重启idea才生 ...

  3. EOS

    1.移植性特别差,例如用Eclipse,idea,等其他集成工具开发之后的项目,难以快速的搭建到EOS集成工具中(例如逻辑流,数据结构等)2.项目框架的局限性大,底层封装的框架或者组件迭代性较差,很难 ...

  4. Java框架spring 学习笔记(五):Bean定义继承

    子 bean 的定义继承父定义的配置数据.子定义可以根据需要重写一些值,或者添加其他值. 编写HelloWorld.java package com.example.spring; public cl ...

  5. 编写一个 rpc

    手动编写一个 RPC 调用 package com.alibaba.study.rpc.framework; import java.io.ObjectInputStream; import java ...

  6. 内网主机使用yum安装软件

    经常遇到这样的情况:有一台内网linux主机需要安装软件,但是主机又无法连接外网,通常情况下可以使用rpm包或者使用源码编译安装.但常常会遇到依赖缺少的情况,这就麻烦了,要一一找到缺少的软件包. 这种 ...

  7. 大数据学习笔记3 - 并行编程模型MapReduce

    分布式并行编程用于解决大规模数据的高效处理问题.分布式程序运行在大规模计算机集群上,集群中计算机并行执行大规模数据处理任务,从而获得海量计算能力. MapReduce是一种并行编程模型,用于大规模数据 ...

  8. aruba 开启802.1X认证

    1.即在ac上指定一个radius server认证 2.创建本地账户测试

  9. ping不通公网ip时路由器设置

    可能是路由器里设置了wan口禁ping了 另外,NAT地址转换不要动,默认是开启的 主服务器上防火墙关掉或者设置好访问规则 默认的80端口是不能用的,需要设置一个其它的端口

  10. java 编程英语单词,语句

    记录一下java 编程工作学习中常用的英语汇总 in other words: 换句话说 dangle :悬挂 separated:分开的 distinct:明显的,独特的 actual :实际的 i ...