今天试了一下node.js 创建一个服务居然如此的简单,没忍住要分享给大家!
brew cask install node
You can use Connect and ServeStatic with Node.js for this:
1.Install connect and serve-static with NPM
$ npm install connect serve-static 2.Create server.js file with this content:
var connect = require(‘connect’); var serveStatic = require(‘serve-static’); connect().use(serveStatic(“/Users/jiangtao/site/ “)).listen(8080); 3.Run with Node.js
$ node server.js You can now go to http://localhost:8080/yourfile.html
把文件放在/Users/jiangtao/site/ 目录就好
示例文件下载:ex.js
Like Be the first to like this
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100445.html原文链接: