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. day50 盒子显隐2D形变

    复习 1.浮动布局 解决block盒子同行显示 => 不完全脱离文档流 => 不再撑开父级高度 脱离文档流: 不在页面中占位(显示层次高于文档流) 不完全: 可以通过清浮动操作, 让子级重 ...

  2. PhoenixFD插件流体模拟——UI布局【Interaction】详解

    流体交互 本文主要讲解Interaction折叠栏中的内容.原文地址:https://docs.chaosgroup.com/display/PHX3MAX/Liquid+Interaction 主要 ...

  3. SQl 执行效率总结

    SQL执行效率总结 1.关于SQL查询效率,100w数据,查询只要1秒,与您分享: 机器情况 p4: 2.4 内存: 1 G os: windows 2003 数据库: ms sql server 2 ...

  4. keepalived vip 没有生成或者生成了ping不通?

    1 问题现象:keepalived已启动但vip 没有生成./var/log/messages日志不断刷屏 tail /var/log/messages Nov :: cache-redis- Kee ...

  5. <a>超链接用作下载

    在a标签里添加  download=""  ,“ ”里面的内容可随意写,比如文件名. <a href="/download/武林秘籍.pdf" downl ...

  6. sql yog出现2013错误

    首先用telnet检查一下你的防火墙端口,如果连接失败,配置防火墙. 配置防火墙,开启3306端口 find -name iptables vim /etc/sysconfig/iptables -A ...

  7. Style- DataTrigger例子(Text长度)

    Text长度小于7时,边框变为红色 <Window.Resources> <local:L2BConverter x:Key="cvtr"/> <St ...

  8. String、StringBuilder、StringBuffer 区别

    public static void testStringBuffer(){ long start System currentTimeMillis(); StringBuffer sbuf = ne ...

  9. 关于js中操作数组的一些方法

    网上找的通篇看了一遍讲的很透收藏了!  转自(https://www.cnblogs.com/blogs-8888/p/6518683.html) 1.锁定数组的长度(让数组的长度变成只读). 1 2 ...

  10. rpm --rebuilddb

    rpm -ivh .....rpm 报Bus Error rpm --rebuilddb