Skip to content

suzuhe481/node-express-quick-start-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Quick Start Guide for Node.js Express Apps

I created this guide to help me when starting a new Express app. I took note of the starting steps needed as well as some helpful packages/middlewares.

Getting Started

  • This guide assumes you understand how Node.js and Express applications work, and you just need help with the initial set up.
  • The following instructions are assuming you are using the Linux OS. I use Ubuntu.
  • Make sure to have the LTS (Long Term Support) of Node to avoid errors.

Table of Contents

  1. Prerequisite
  2. Creating the App
  3. Packages
  4. Middleware

[1] Prerequisite

  • Install Express Application generator globally so you can create Express apps.
npm install express-generator -g

[2] Creating the App

  • Deciding on a template library for your project such as EJS, Pug(Jade), Hbs, etc.

  • Open a terminal instance in the directory you want to create your project folder and run the following command replacing VIEW_TEMPLATE with the template you will use.

express my-first-express-app --view=VIEW_TEMPLATE
  • E.g. If I wanted to create an app named super-cool-app using the EJS template, I would run...
express super-cool-app --view=ejs
  • This creates an Express app with some folders, an app.js and package.json files.

  • NOTE: For the following steps, I will assume the app's name is super-cool-app.

  • Follow the termianl instructions to go to the project directory, install packages, and run the app.

cd super-cool-app
npm install
DEBUG=super-cool-app:* npm start

[3] Packages

Here are some helpful packages you can use for your React projects.

  • Automatically restarts the Node.js application when there are file changes.
npm install --save-dev nodemon
  • Additionally, go to your package.json file and edit the scripts to the following, replacing the app name below with your app name.
"scripts": {
    "start": "node ./bin/www",
    "devstart": "nodemon ./bin/www",
    "serverstart": "DEBUG=super-cool-app:* npm run devstart"
  },
  • Now, to run your applications, just run this in the command line.
npm run serverstart

  • A helpful way to format time using JavaScript.

  • Object modeling tool for MongoDB.

  • Handles environment variables and secrets.

[4] Middleware

Here's some useful middleware you can use in your Express projects.

  • Handles exceptions for async express routes.

  • Allows for sanitation and validation data.

  • Compresses the HTPP response sent to the client to reduce load times.

  • Protects against vulnerabilities by setting appropriate HTTP headers.

  • Limits repeated requests to public APIs and/or endpoints.

  • Handles authentication and sessions

  • Encryption for hashing passwords.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors