[express] getting started

김기용·2021년 1월 28일
1
post-thumbnail
post-custom-banner

⚡️ 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

profile
매일 새로운 배움을 통해 꾸준히 성장하는 것을 목표를 두고 있습니다. 논리적인 사고로 문제해결 하는것에 희열을 느끼고 언젠가 제가 만든 결과물들이 사람들에게 편이를 제공하며 사용되는 날을 간절히 소망하고 있습니다. 🙏
post-custom-banner

0개의 댓글