basic-node-server 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +11 -15
  2. package/bns.js +8 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,31 +2,27 @@
2
2
  Basic node server for everyone.
3
3
 
4
4
  Basic node server simply hosts and serves files from the current project directory through HTTP.
5
- If no path is given, it will serve the index.html file.
5
+ If no path is given, it will serve the index.html file in the root directory.
6
+
7
+ ## Installation
6
8
 
7
- ## How to use
8
9
  ```
9
- node bns [port]
10
+ npm install basic-node-server
11
+
10
12
  ```
11
13
 
12
- The [port] argument is optional. If no port is given, it will default to 3000.
14
+ ## Usage
13
15
 
14
- For example, if you want to serve the current directory on port 8080, you would run:
16
+ Then, you can run it from your project directory:
15
17
 
16
18
  ```
17
- node bns 8080
18
- ```
19
-
20
- ## NPM
21
- This package is also available on NPM. To install it, run:
22
-
19
+ npx bns [port]
23
20
  ```
24
- npm install basic-node-server
25
21
 
26
- ```
22
+ The [port] argument is optional. If no port is given, it will default to 3000.
27
23
 
28
- Then, you can run it from your project directory:
24
+ For example, if you want to serve the current directory on port 8080, you would run:
29
25
 
30
26
  ```
31
- node node_modules/basic-node-server/bns [port]
27
+ node bns 8080
32
28
  ```
package/bns.js CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env node
2
+
1
3
  const http = require('http');
2
4
  const fs = require('fs');
3
5
  const path = require('path');
@@ -23,6 +25,12 @@ const server = http.createServer((req, res) => {
23
25
  // Extract the file path from the request URL
24
26
  let filePath = path.join(process.cwd(), req.url);
25
27
 
28
+ // check if its a get request
29
+ if (req.method !== 'GET') {
30
+ res.statusCode = 405;
31
+ res.end('Method not allowed');
32
+ }
33
+
26
34
  // remove get query string
27
35
  filePath = filePath.split('?')[0];
28
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basic-node-server",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Basic node server for everyone.",
5
5
  "main": "bns.js",
6
6
  "scripts": {