Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

-FA
-FA

Posted on

     

Express.js boilerplate cheatsheet

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

  • Download and install node.js fromhttps://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 fileindex.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:
constexpress=require('express')constapp=express()constport=3000app.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
  • Openlocalhost:3000 to view in browser - should show:Hello World!

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
msamgan profile image
Mohammed Samgan Khan
Love to code with a DRY KISS

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.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Weekend coder since the C64
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp