on windows
set PORT=4000
dotenv => https://github.com/motdotla/dotenv
further reading on env vars and dotenv: https://dev.to/deammer/loading-environment-variables-in-js-apps-1p7p
const port = process.env.PORT || 3000;
const fs = require("fs");
const axios = require("axios");
async function getUsers() {
let { data: users } = await axios.get(
"https://jsonplaceholder.typicode.com/users"
);
users = JSON.stringify(users);
fs.writeFile("./test.txt", users, function(err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
}
getUsers();
const path = require("path");
module.exports = path.dirname(process.mainModule.filename);
// the public dir will be readable by the client
app.use(express.static(path.join(__dirname, "public")));
router.get("/add-product", (req, res, next) => {
res.sendFile(path.join(rootDir, "views", "add-product.html"));
});