Advertisement
wcchuo

Simple JS Fileserver

Jan 28th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express    = require('express'),
  2.       cors       = require('cors'),
  3.       serveIndex = require('serve-index'),
  4.       port       = 9999
  5.       app        = express()
  6.  
  7. app.use(cors())
  8.  
  9. app.get('/', (req, res)=>{res.send(`<html><body><h1>Server running at port 9999</h1><h2><a href="/public">View files</a></h2></body></html>`)})
  10.  
  11. app.use('/public', express.static('public'), serveIndex('public', {'icons': true}))
  12.  
  13. app.listen(9999, ()=>console.log(`Server is listening at port ${port}`))
  14.  
  15.  
  16.  
  17.  
  18. {
  19.   "name": "server",
  20.   "version": "1.0.0",
  21.   "description": "",
  22.   "main": "app.js",
  23.   "scripts": {
  24.     "test": "echo \"Error: no test specified\" && exit 1"
  25.   },
  26.   "author": "",
  27.   "license": "ISC",
  28.   "dependencies": {
  29.     "cors": "^2.8.5",
  30.     "express": "^4.16.4",
  31.     "serve-index": "^1.9.1"
  32.   }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement