1. Create a new project file and create an entry file server.js
2. Initialize
npm init
3. Install express
npm install express
4. Write file entry (server.js) in
const express = require('express') const app = express() app.get("/",(req,res) => { res.send("Hello world!"); }) const port = process.env.PORT || 5000 //端口 app.listen(port,() => { console.log('Server runing on port $(port)') })
5. Run node
node server.js
6. When the code changes every time you need to re-run the node server.js this time is not convenient, you can install nodemon
npm install nodemon -g run nodemon server.js automatic update (before we use node server.js)
7. Modify the package configuration
{ "name": "app", "version": "1.0.0", "description": "restful api", "main": "server.js", "scripts": { "start":"node server.js", "server":"nodemon server.js" }, "author": "Baibu", "license": "ISC", "dependencies": { "express": "^4.17.1" } }
1. Create a new project file and create an entry file server.js
2. Initialize
npm init
3. Install express
npm install express
4. Write file entry (server.js) in
const express = require('express') const app = express() app.get("/",(req,res) => { res.send("Hello world!"); }) const port = process.env.PORT || 5000 //端口 app.listen(port,() => { console.log('Server runing on port $(port)') })
5. Run node
node server.js
6. When the code changes every time you need to re-run the node server.js this time is not convenient, you can install nodemon
npm install nodemon -g run nodemon server.js automatic update (before we use node server.js)
7. Modify the package configuration
{ "name": "app", "version": "1.0.0", "description": "restful api", "main": "server.js", "scripts": { "start":"node server.js", "server":"nodemon server.js" }, "author": "Baibu", "license": "ISC", "dependencies": { "express": "^4.17.1" } }