This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
forked from team-photon/business-landing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
54 lines (47 loc) · 1.59 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"use strict";
var gulp = require('gulp');
var nodemon = require('gulp-nodemon');
var mongodb = require('mongodb');
var fs = require('fs');
gulp.task('runSite', function() {
nodemon({script: 'server.js'});
});
gulp.task('runApi', function() {
nodemon({script: 'api/server.js', ext: 'js', watch: ['api']});
});
gulp.task('loadZipData', function() {
fs.readFile('zipdata.txt', function(err, data) {
if (err) {
throw err;
}
let dataString = data.toString();
let lines = dataString.split(/\r?\n/);
let zipCoordinates = [];
lines.forEach((line) => {
if (line.trim() != '') {
let fields = line.split('\t');
var coords = {
zip: fields[0].trim(),
lat: fields[5].trim(),
lng: fields[6].trim()
};
zipCoordinates.push(coords);
}
});
// Connection URL
let mongoUrl = 'mongodb://localhost:27017/businesslanding';
// Use connect method to connect to the Server
mongodb.MongoClient.connect(mongoUrl, function(err, db) {
console.log("Connected correctly to server");
let collection = db.collection('zipCoordinates');
collection.deleteMany({}, function(err, results) {
collection.insertMany(zipCoordinates, function(err, result) {
if (err !== null) {
console.log(err);
}
db.close();
});
});
});
});
});