DEV Community

-FA
-FA

Posted on

1 2

Express.js boilerplate cheatsheet

This is the bare minimum cheatsheet to get express.js up and running.

  • Download and install node.js from https://nodejs.org/en/download/
  • Open terminal or commandline
  • Creat a project directory and change to it
  • Run terminal command: npm init (accept all defaults by pressing enter)
    • This will create package.json file, which has basic project configuration
  • Run terminal command: npm i express
    • This installs express.js
  • Run terminal command: npm i -g nodemon
    • Installs node monitor, which will make sure server is restared on file saves
  • Create new file index.js (which is referenced in the package.json file created above)
  • Add the following starter code to index.js, which is the bare minimum to get it going:
    const express = require('express')
    const app = express()
    const port = 3000

    app.get('/', (req, res) => res.send('Hello World!'))

    app.listen(port, () => console.log(`Example app listening on port ${port}!`))
  • Run terminal command: node index.js to run it
  • or run terminal command: nodemon index.js to run it via nodemon - this will ensure that server is restarted automatically whenever there is a file change
  • Open localhost:3000 to view in browser - should show: Hello World!

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (1)

Collapse
 
msamgan profile image
Mohammed Samgan Khan •

hi, nice article.
but going through this much hustle, everytime you create a new setup is a headache.
create-express-boilerplate.com/ helps you out here for the same.
it provides you quick start with everything you need.check it out.

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay