[express] getting started

amuse·2021년 1월 28일
post-thumbnail

⚡️ Create project directory

mkdir node-first-project 
cd    node-first-project

Create project directory and move into it. This directory will be your project root directory.


⚡️ Create package.json

npm init

if you need more information about package.json, click the link below.
ref(공식문서) - https://docs.npmjs.com/cli/v6/configuring-npm/package-json/


⚡️ Install express & nodemon

npm install express nodemon

Installing express and nodemon sametime.

🕹 about nodemon

💡 When you launch your node.js application with Nodemon it will monitor for any changes and automatically restart the server, improving your productivity.


⚡️ Check your package(express, nodemon)

if you check your package.json, it holds your packages that you've just installed(express, nodemon).

{
  ...
  "dependencies":{
    "express": "^4.17.1",
    "nodemon": "^2.0.7"
  
}

⚡️ Listening server

🕹 Usage: npm commands

npm run <foo>      run the script named <foo>

🕹 package.json: Setting up npm script

{...
    "script":{
	"server": "nodeman app.js"
    },
 ...
}
app.listen(3000);

⚡️ Start Routes

app.get('/', (req, res) => {
  res.send('halo m8');
});

⚡️ What is middlewares ?

app.use('/', () => {
  console.log('This is middleware running');
});

ref -- https://expressjs.com/ko/guide/using-middleware.html

0개의 댓글