basic-node-server 1.0.1 → 1.0.2
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.
- package/README.md +14 -0
- package/index.js +5 -11
- package/mime.json +1203 -0
- package/package.json +1 -1
- package/application.csv +0 -1578
package/README.md
CHANGED
|
@@ -15,3 +15,17 @@ For example, if you want to serve the current directory on port 8080, you would
|
|
|
15
15
|
```
|
|
16
16
|
npm run bns 8080
|
|
17
17
|
```
|
|
18
|
+
|
|
19
|
+
## NPM
|
|
20
|
+
This package is also available on NPM. To install it, run:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
npm install basic-node-server
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then, to run it, run from your project directory:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
node node_modules/basic-node-server/index.js [port]
|
|
31
|
+
```
|
package/index.js
CHANGED
|
@@ -4,22 +4,16 @@ const path = require('path');
|
|
|
4
4
|
|
|
5
5
|
const port = process.argv[2] || 3000; // Set the port from the command line argument or default to 3000
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const mimeJson = path.join(__dirname, '/mime.json');
|
|
8
8
|
|
|
9
9
|
const getContentType = (() => {
|
|
10
10
|
return new Promise((resolve, reject) => {
|
|
11
|
-
fs.readFile(
|
|
11
|
+
fs.readFile(mimeJson, 'utf8', (err, data) => {
|
|
12
12
|
if (err) {
|
|
13
13
|
reject(err);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.reduce((map, [extension, contentType]) => {
|
|
18
|
-
map[extension] = contentType;
|
|
19
|
-
return map;
|
|
20
|
-
}, {});
|
|
21
|
-
|
|
22
|
-
resolve(contentTypeMap);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
resolve(data);
|
|
23
17
|
}
|
|
24
18
|
});
|
|
25
19
|
})
|