Skip to content

Commit e68612e

Browse files
committed
Switch to ES Modules
1 parent 38745d8 commit e68612e

File tree

7 files changed

+30
-29
lines changed

7 files changed

+30
-29
lines changed

bot.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Imports
2-
const { Bot } = require("grammy");
3-
const { BOT_TOKEN, ADMINS, LIMIT } = require("./config");
4-
const { isUrl, getRandomId, getProductDetails } = require("./utils");
5-
const { manageProducts, manageUsers } = require("./db");
6-
const unshort = require("./unshort");
2+
import { Bot } from "grammy"
3+
import { BOT_TOKEN, ADMINS, LIMIT } from "./config.js"
4+
import { isUrl, getRandomId, getProductDetails } from "./utils.js"
5+
import { manageProducts, manageUsers } from "./db.js"
6+
import unshort from "./unshort.js"
77

88
const bot = new Bot(BOT_TOKEN); // Initialize bot
99

@@ -257,4 +257,4 @@ bot.catch((err) => {
257257

258258
setInterval(track, 3600000); //Track every hr.
259259

260-
module.exports = bot;
260+
export default bot;

config.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require('dotenv').config()
1+
import 'dotenv/config'
22

33
// Check if bot token is there or not
44
if(!process.env.BOT_TOKEN) {
@@ -11,11 +11,11 @@ if(!process.env.DB_URL) {
1111
process.exit(1);
1212
}
1313

14-
module.exports = {
15-
ADMINS: process.env.ADMINS || '',
16-
BOT_TOKEN: process.env.BOT_TOKEN || '',
17-
DB_URL: process.env.DB_URL || '',
18-
WORKER_URL: process.env.WORKER_URL || '',
19-
API_KEY: process.env.API_KEY || '', // Generate any API Key and pass it when accessing the API.
20-
LIMIT: Number(process.env.LIMIT), // Maximum number of products can be added by a user at a time.
21-
}
14+
const ADMINS = process.env.ADMINS || ''
15+
const BOT_TOKEN = process.env.BOT_TOKEN || ''
16+
const DB_URL = process.env.DB_URL || ''
17+
const WORKER_URL = process.env.WORKER_URL || ''
18+
const API_KEY = process.env.API_KEY || '' // Generate any API Key and pass it when accessing the API.
19+
const LIMIT = Number(process.env.LIMIT) // Maximum number of products can be added by a user at a time.
20+
21+
export { ADMINS, BOT_TOKEN, DB_URL, WORKER_URL, API_KEY, LIMIT }

db.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const {DB_URL} = require('./config');
2-
const MongoClient = require('mongodb').MongoClient;
1+
import {DB_URL} from './config.js';
2+
import {MongoClient} from 'mongodb';
33
var mongo;
44

55
// Check if mongodb is connected or not
@@ -65,4 +65,4 @@ const manageProducts = async(data, action) => {
6565
}
6666
}
6767

68-
module.exports = {manageProducts, manageUsers};
68+
export {manageProducts, manageUsers};

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const { getRandomId, getProductDetails } = require("./utils");
2-
const { manageProducts, manageUsers } = require("./db");
3-
const {API_KEY} = require('./config');
4-
const express = require('express');
5-
const bot = require('./bot');
1+
import { getRandomId, getProductDetails } from "./utils.js"
2+
import { manageProducts, manageUsers } from "./db.js"
3+
import {API_KEY} from './config.js'
4+
import express from 'express'
5+
import bot from './bot.js'
66

77
//Globals
88
const port = process.env.PORT || 3000;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"type": "git",
1212
"url": "git+https://github.com/AffanTheBest/price-tracker.git"
1313
},
14+
"type": "module",
1415
"keywords": [
1516
"price-tracker",
1617
"amazon",

unshort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const axios = require('axios');
1+
import axios from 'axios';
22
const unshort = async (url) => {
33
const extractUrl = req => req?.request?.res?.responseUrl ||
44
req?.request?._redirectable?._currentUrl ||
@@ -16,4 +16,4 @@ const unshort = async (url) => {
1616
return longUrl;
1717
}
1818

19-
module.exports = unshort;
19+
export default unshort;

utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const cheerio = require('cheerio');
2-
const axios = require('axios');
3-
const {WORKER_URL} = require('./config');
1+
import cheerio from 'cheerio'
2+
import axios from 'axios'
3+
import {WORKER_URL} from './config.js'
44

55
const urlRegex = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
66

@@ -54,4 +54,4 @@ const getProductDetails = async(url, merchant) => {
5454
}
5555
}
5656

57-
module.exports = { isUrl, getRandomId, getProductDetails };
57+
export { isUrl, getRandomId, getProductDetails };

0 commit comments

Comments
 (0)