Skip to content

Commit e36ea0b

Browse files
author
Andrey
committed
Small refactor according to Node.js best practices
- moved any server related functioonality under server.js - simplified app.js a bit - introduced config.env file
1 parent fcd8347 commit e36ea0b

File tree

11 files changed

+19
-9
lines changed

11 files changed

+19
-9
lines changed

index.js renamed to app.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const fs = require('fs');
33
const path = require('path');
44
const { PDFNet } = require('@pdftron/pdfnet-node');
55
const mimeType = require('./modules/mimeType');
6-
const port = 9000;
76
const filesPath = './files';
87

98
const app = express();
@@ -268,10 +267,4 @@ const PDFNetEndpoint = (main, pathname, res) => {
268267
});
269268
};
270269

271-
app.listen(port, () =>
272-
console.log(
273-
`nodejs-convert-file-server listening at http://localhost:${port}`,
274-
),
275-
);
276-
277270
module.exports = app;

config.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PORT=9000

files/document.docx.pdf

5 Bytes
Binary file not shown.

files/new.pdf

-54 Bytes
Binary file not shown.

files/optimized_webviewer.pdf

2 Bytes
Binary file not shown.
460 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"description": "This is an example how to use PDFTron Custom Server - Node JS SDK",
55
"main": "index.js",
66
"scripts": {
7-
"start": "nodemon index.js",
7+
"start": "nodemon server.js",
88
"test": "mocha --timeout 10000"
99
},
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
1313
"@pdftron/pdfnet-node": "^7.1.1",
14+
"dotenv": "^8.2.0",
1415
"express": "^4.17.1",
1516
"nodemon": "^2.0.3"
1617
},

server.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const dotenv = require('dotenv');
2+
dotenv.config({ path: './config.env' });
3+
4+
const app = require('./app');
5+
6+
const port = process.env.PORT;
7+
8+
app.listen(port, () => {
9+
console.log(`nodejs-convert-file-server listening at http://localhost:${port}`);
10+
});

0 commit comments

Comments
 (0)