Phillippe Santana
PhillCode

Follow

PhillCode

Follow
NodeJS Console App with ES6 - Starter Project

Photo by Pankaj Patel on Unsplash

NodeJS Console App with ES6 - Starter Project

Phillippe Santana's photo
Phillippe Santana
·Aug 31, 2022·

1 min read

Sometimes you just need a place to start coding and see results!

This is a quick tutorial on how to start a project for a Console App, in NodeJS, with ES6 support.

Lean and mean 😎

1) Create your project folder and enter it

2) Run npm init -y

image.png

3) Install the following packages:

yarn add @babel/core @babel/node @babel/preset-env nodemon --D

image.png

4) Create the .babelrc file in the root, and paste this as content:

{
  "presets": ["@babel/preset-env"]
}

5) Edit package.json

  • Add "type": "module"
  • Add "start": "nodemon --exec babel-node src/index.js" to the scripts

image.png

6) Create src/index.js to write your code

7) Run with yarn start

image.png


Additional capabilities 📦

Environment variables

  1. Install dotenv with yarn add dotenv
  2. Create the .env file and add your variables
  3. Add import "dotenv/config"; at the top of your index.js
  4. Use your variables in code

image.png

API access

  1. Install node-fetch with yarn add node-fetch
  2. Add import fetch from "node-fetch"; at the top of your index.js
  3. Make your API calls

image.png

Async and await

  1. Add an async IIFE like (async function main() { /*code here*/ })();
  2. Add your awaited code inside

image.png

 
Share this