Browse Source

Do not crash if folder already exists

Johannes Zellner 6 years ago
parent
commit
4baff1c4e3
1 changed files with 5 additions and 5 deletions
  1. 5 5
      index.js

+ 5 - 5
index.js

@@ -22,16 +22,16 @@ var opts = {
 //Creates webcam instance
 var Webcam = NodeWebcam.create(opts);
 
-Webcam.list(function (list) {
-    console.log(list)
-});
-
 const app = express();
 const port = 3000;
 const picturePath = path.resolve('public/pictures');
 
 console.log('Using picture path at:', picturePath);
-fs.mkdirSync(picturePath);
+try {
+    fs.mkdirSync(picturePath);
+} catch (e) {
+    if (e.code !== 'EEXIST') console.log(e);
+}
 
 app.get('/pictures', function (req, res, next) {
     var entries = fs.readdirSync(picturePath);