1.0.4 • Published 7 years ago
good-server v1.0.4
Good Server
Launch simple express server from CLI (with JSON, static files hosting and file upload support)
Install CLI Tool
using npm (restricted ATM)
npm install -g good-serverwith npx (restricted ATM)
npx good-server [Options]using local code
cd good-server (clone)
npm install -g ./Command Line Interface
good-server --help
Usage: good-server [options]
Options:
-V, --version output the version number
-d, --dir [dir] Distrubution folder/directory (local or absolute path) (default: ./dist)
-u, --upload [dir] Upload folder/directory (local or absolute path) (default: ./upload)
-p, --port [port] Custom port for server (default: null)
-h, --host [host] Host for the server (default: localhost)
-s, --secure Secure host server (https)
-f, --file-input-name [fileInputName] File input name (default: file)
--no-open Do not open URL in browser
-help output usage informationUsage
good-server: Serve./distfolder and use./uploadfolder for upload files access/upload.good-server --no-open: Do not open browser when server starts.good-server -p 3000: Use port3000for server instead of default random available port.good-server -h 192.168.0.9: Use host192.168.0.9instead of defaultlocalhost.good-server -s: Usehttps://protocol instead of defaulthttp://for server.good-server -f image: Useimageas file input name in request body instead of defaultfile.good-server -d ./build: Use./buildfolder as distribution folder instead of default./dist. This can be absolute path on the system as well, like/usr/share/build.good-server -u ./files: Use./filesfolder to serve/upload files instead of default./upload. This can be absolute path on the system as well, like/usr/share/files.
API Access
- GET
/file.extpath on server URL will servefile.extfile from distribution folder. - GET
/folder/file.extpath on server URL will serverfile.extfromfolderdirectory inside distribution folder. - Server will add appropriate header while serving these files. For example, GET
/json/users.jsonwill serveusers.jsonfromjsondirectory withapplication/jsonContent-Type response header. - GET
/upload/file.extwill servefile.extfile from upload folder. - POST
/uploadroute is used to upload a file. Make sure to use correct file input name while uploading a file to this route. This is key in your multipart form data. When you start a server, upload folder is automatically created if doesn't exist.
Websockets
v1.0.4+ supports websocket on the same port of web server. Default ping-pong event is message. Use Online client tool to test websocket functionality. Use http://localhost:{port} as socket.io server URL.
