- Basic Requirement
- node.js
- steps to make simple api
- crate a new folder
- open that folder in vs code
- Open the new terminal
- Run the command
- npm init && npm i && npm i express && npm i mongodb && npm i mongoose && npm i nodemon --save-dev
- write the nessesory things like package name and press enter , enter till auther name apperes , enter auther name and press enter again
- open package.json file and write search for
- "scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}, - and replace it with"scripts": {"test": "echo \"Error: no test specified\" && exit 1","start":"nodemon index.js"}
- Now create a new file index.js and write the following code
- const express = require('express');const app = express();console.log("Hello World ");const port = process.env.PORT || 3000;app.listen(port, () => {console.log(`Server listening on port ${port}`);});
- Now open the new terminal and run the command npm start
- You will see the following output
Comments
Post a Comment