Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mahendran-balaji/setup-env-for-nodejs-project
Setup ENV for nodejs Project
https://github.com/mahendran-balaji/setup-env-for-nodejs-project
dotenv nodejs
Last synced: about 2 months ago
JSON representation
Setup ENV for nodejs Project
- Host: GitHub
- URL: https://github.com/mahendran-balaji/setup-env-for-nodejs-project
- Owner: Mahendran-Balaji
- Created: 2023-07-22T19:00:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-23T18:35:27.000Z (over 1 year ago)
- Last Synced: 2024-11-14T22:08:52.071Z (about 2 months ago)
- Topics: dotenv, nodejs
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Setup .env for Node JS project
Step 1: Setup new npm package
```bash
npm init
```
Step 2 : Install the following package: dotenv```bash
npm install dotenv
```
Step 3: Create a new .env file in the root directoryStep 4: Add Following Code into the .env file
```javascript
PORT_NUMBER=3000
```
Step 5 : To create index.js file add following code```javascript
const path = require('path');
const express = require("express");
const app = express();
const dotenv = require("dotenv").config({path:path.resolve('.env')});
const env = dotenv.parsed;const portNumber = env.PORT_NUMBER;
app.get("/", (req, res) => {
res.send("Hello Friends!");
});app.listen(portNumber, () => {
console.log(`Example app listening on port ${portNumber}!`);
});```
Step 6: Run the application```bash
node index.js
```## Author
- [@Mahendran-Balaji](https://github.com/Mahendran-Balaji/)