package.json file
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon --env-file=.env index.js",
"start": "node --env-file=.env index.js",
"prod": "node --env-file=.env.prod index.js",
"local": "node --env-file=.env.local index.js",
"build": "node --env-file=.env build.js",
"clean": "node --env-file=.env clean.js"
},
Create A new Project
mkdir test_env
cd test_env
open terminal and write this commend
npm init -y
touch .env
write code .env file
# write code .env file
PORT = 3333
MONGO_DB_URL = mongodb+srv://<username>:<password>@<cluster>.mongodb.net/<database>?retryWrites=true
PRIVATE_KEY = <private_key>
touch index.js
import express from "express";
import mongoose from "mongoose";
const app = express();
app.listen(process.env.PORT | 3000, () => {
console.log(` Listening on port ${process.env.PORT}`)
})
mongoose.connect(process.env.MONGO_DB_URL, {
dbName: "test",
authSource: "admin"
})
.then(() => {
console.log("Connected to MongoDB");
})
.catch((err) => {
console.log(err);
})
Top comments (0)