1

node App.js works, but npm start doesn't works.

I just followed this nodejs tutorial (tutorial is written by Korean).

I tried to change code to:

"scripts": { "start": "webpack-dev-server" } but it didn't work.

this is my code: App.js

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

package.json

{
  "name": "codlab-nodejs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node js"
  },
  "author": "",
  "license": "ISC"
}

package-lock.json

{
  "name": "codlab-nodejs",
  "version": "1.0.0",
  "lockfileVersion": 1
}

This is the err msg.

C:\Users\김동희\codlab-nodejs>npm start

> [email protected] start C:\Users\김동희\codlab-nodejs
> node js

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'C:\Users\김동희\codlab-nodejs\js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\김동희\AppData\Roaming\npm-cache\_logs\2019-08-03T14_03_42_211Z-debug.log
0

2 Answers 2

4

In your package.json change the value of the property "start".

Replace:

"start": "node js"

With:

"start": "node App.js"
Sign up to request clarification or add additional context in comments.

Comments

2

The start npm script is trying to run a file called js, which does not exist and consequently fails.

Instead, set your start npm script to be the correct command that asks Node.js to run your App.js file.

Your package.json would include something like this:

  "scripts": {
    "start": "node App.js"
  }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.