1. Development Web Servers
- http-server: Ultra -simple, Single command serves current directory
- live-server: Lightweight, Support live-reloading
- Express: Comprehensive, Highly Configurable, Production grade, Can run it everywhere
- budo: Integrates with Browserify, Includes hot reloading
- Webpack dev server: Built in to Webpack, Serves from memory, Includes hot reloading
- Browsersync: Dedicated IP for sharing work on LAN. ==All interactions remain in sync!== Great for cross-device testing. Integrates with Webpack, Browserify, Gulp
1.1. Express setup
/** express dev server */
let express = require('express');
let path = require('path');
let open = require('open');
let port = 3000;
let app = express();
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '../src/index.html'));
});
app.listen(port, (err) => {
if (err) {
console.log(err);
} else {
open(`http://localhost:${port}`);
}
});
1.2. Sharing work-in-progress
- localtunnel
- ngrok
- Surge
- now
1.2.1. localtunnel (great!)
Easiest setup Ultra-versatile. Easily share work on your local machine. 让内网服务器暴露到公网上的开源项目
Setup:
1. `npm install localtunnel -g`
2. Start your app, if port is 3000
3. `lt --port 3000` or `lt --port 3000 --subdomain wghglory`
Result is like:
your url is: https://pgerjpkszz.localtunnel.me or https://wghglory.localtunnel.me
Note: multiple devices, use browserSync and localtunnel together
1.2.2. ngrok
Easy setup Secure. Secure tunnel to your local machine
- Sign up
- Install ngrok
- Install authtoken
- Start your app
./ngrok http 80
1.2.3. now
No firewall hole Hosting persists. Quickly deploy Node.js to the cloud
npm install -g now
- Create start script
now
1.2.4. Surge
No firewall hole Hosting persists. Quickly host static files to public URL
npm install -g surge
surge