A developer initiates a server with the file server.js and adds dependencies in the source code ' s package.json that are required to run the server.
Which command should the developer run to start the server locally?
node start
npm start
npm start server.js
start server.js
Comprehensive and Detailed Explanation From JavaScript/Node.js Knowledge:
In a Node.js project that uses package.json, you typically define a " start " script:
{
" scripts " : {
" start " : " node server.js "
}
Then you start the app with:
npm start:
Looks up the " start " script in package.json.
Runs the command defined there (commonly node server.js).
This is the standard way to start a Node.js app with npm-managed dependencies.
Why others are incorrect:
A. node start
Tries to run a file named start with Node; does not use package.json scripts.
C. npm start server.js
npm start does not take the script filename as an argument in this way; it just runs the start script as defined.
D. start server.js
Not an npm or node command; on some shells it just tries to “start” a process but is not the standard Node/npm workflow.
Relevant concepts: package.json, npm scripts, npm start, Node entry file execution.
Submit