Exercise - Configure the package.json
You're a Node.js developer at Tailwind Traders. Knowing how to set up a new Node.js project is an important skill to have. Setup includes generating a manifest file and creating some common scripts that you're likely to use throughout the project lifecycle.
Set up a new Node.js project
Open a terminal window.
Clone the
https://github.com/MicrosoftDocs/node-essentials/repo by running this command:git clone https://github.com/MicrosoftDocs/node-essentials/Change to the folder that has the cloned files for this exercise:
cd node-essentials/node-dependencies/3-exercise-package-jsonIn this folder, you should see a src subfolder with an index.js file:
-| src/ ---| index.jsRun the following command to initialize a Node.js project:
npm init -yThis command generates a package.json file that looks similar to this example:
{ "name": "<your project>", "version": "1.0.0", "description": "", "main": "script.js", "dependencies": {}, "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" }Edit the package.json file and modify these property values:
name: "tailwind-trader-api"description: "HTTP API to manage items from the Tailwind Traders database"main: "index.js"keywords: ["api", "database"]author: "Sam"
Your package.json file should now look like this code:
{ "name": "tailwind-trader-api", "version": "1.0.0", "description": "HTTP API to manage items from the Tailwind Traders database", "main": "index.js", "dependencies": {}, "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": ["api", "database"], "author": "Sam", "license": "ISC" }In the
scriptssection, add this definition for thestartaction before the definition for thetestaction:"start": "node ./src/index.js",Save your changes and close the package.json file.
Start your project with the
startaction by entering this command:npm startYou should see this output:
Welcome to this application
You now have a good file structure that you can build upon as your project grows.
Trebate pomoć? Pogledajte naš vodič za rješavanje problema ili pošaljite željene povratne informacije prijavljivanjem problema.