javascript - Node.Js Cannot find module, module.js:471 -
i started learning node.js today. downloaded recent version. have run several issues along way able solved of them besides 1 error keep getting:
error: cannot find module 'c:\users\dennis\sample.js' @ function.module._resolvefilename (module.js:469:15) @ function.module._load (module.js:417:25) @ module.runmain (module.js:604:10) @ run (bootstrap_node.js:389:7) @ startup (bootstrap_node.js:149:9) @ bootstrap_node.js:504:3
this code, sample js code got w3schools.
<script> var http = require('http'); http.createserver(function (req, res) { res.writehead(200, {'content-type': 'text/plain'}); res.end('hello world!'); }).listen(8080); </script>
my nodejs folder in c:\program files\nodejs. put sample.js file inside folder , had no luck. copy sample file , put under path c nodejs, still nothing.
any tip appreciated.
i'm sure w3schools wouldn't put that in tutorials.
your file should contain only:
var http = require('http'); http.createserver(function (req, res) { res.writehead(200, {'content-type': 'text/plain'}); res.end('hello world!'); }).listen(8080);
<script>
tags belong in html pages (or templates, etc.).
also, no file name not need end .js
node interpret it. happen require()
statements ask file , not specify extension default file of same name ends .js
.
Comments
Post a Comment