Skip to content

Instantly share code, notes, and snippets.

{
"window.menuBarVisibility": "default",
"workbench.sideBar.location": "left",
"window.zoomLevel": 0,
"git.autofetch": true
}
@dennbagas
dennbagas / server.js
Last active September 17, 2019 11:14
Membuat weather API dengan Node.js
var express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cors());
app.get('/', function (req, res) {
@dennbagas
dennbagas / bmkg_data.js
Last active September 17, 2019 07:10
Link data provinsi BMKG
module.exports = [
"http://data.bmkg.go.id/datamkg/MEWS/DigitalForecast/DigitalForecast-Aceh.xml",
"http://data.bmkg.go.id/datamkg/MEWS/DigitalForecast/DigitalForecast-Bali.xml",
"http://data.bmkg.go.id/datamkg/MEWS/DigitalForecast/DigitalForecast-BangkaBelitung.xml",
"http://data.bmkg.go.id/datamkg/MEWS/DigitalForecast/DigitalForecast-Banten.xml",
"http://data.bmkg.go.id/datamkg/MEWS/DigitalForecast/DigitalForecast-Bengkulu.xml",
"http://data.bmkg.go.id/datamkg/MEWS/DigitalForecast/DigitalForecast-DIYogyakarta.xml",
"http://data.bmkg.go.id/datamkg/MEWS/DigitalForecast/DigitalForecast-DKIJakarta.xml",
"http://data.bmkg.go.id/datamkg/MEWS/DigitalForecast/DigitalForecast-Gorontalo.xml",
"http://data.bmkg.go.id/datamkg/MEWS/DigitalForecast/DigitalForecast-Jambi.xml",
const fs = require("fs");
const bmkg_data = require("./bmkg_data");
const xml = require("xml2js");
const request = require("request");
const async = require("async");
module.exports.get = async () => {
let dataArray = [];
console.log('getting weather data...');
@dennbagas
dennbagas / server.js
Created September 17, 2019 11:16
Updated server.js API weather
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const weather = require("./weather");
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cors());
@dennbagas
dennbagas / index.js
Last active September 17, 2019 12:12
const fs = require("fs");
module.exports.index = async (req, res, next) => {
const rawcity = req.query.kota;
let city;
if (rawcity) {
city = rawcity.toLowerCase()
.split(' ')
.map((s) => s.charAt(0).toUpperCase() + s.substring(1))
@dennbagas
dennbagas / server.js
Created September 17, 2019 12:18
Update ke 3 server.js
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const weather = require("./weather");
// update
const resource = require("./weather/resource");
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
@dennbagas
dennbagas / match_args.sh
Created March 19, 2020 05:54
shell match every args
if [ $# -gt 0 ]; then
for i in "$@"
do
if [[ "$i" =~ ^--case1\S* ]]; then
local args;
args="${i#*=}"
elif [[ "$i" =~ ^--case2\S* ]]; then
@dennbagas
dennbagas / index.js
Last active April 28, 2020 05:02
NodeJS Hello World
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
@dennbagas
dennbagas / Dockerfile
Last active April 28, 2020 05:26
Dockerfile example
# Create node image
FROM node:lts-alpine
# specify the workdir
WORKDIR /app
# copy the files
COPY . /app
# install dependencies