Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
pierom_qwerty

uncaught reference error

Recommended Posts

Posted · Original PosterOP

I am trying to make a chatbot in node.js. Everything is going fine but one thing. When I go to check the code on js.do, I get "JavaScript error: Uncaught ReferenceError: require is not defined on line 4"

 

Here is the code. I think the same error might appear on lines 5 and 6 also.

 

<script>
'use strict'

const express = require('express')
const bodyParser = require('bodyparser')
const request = require('request')

const app = express()

app.set('port', (process.env.PORT || 5000))

// Allows to process the data
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())

// Routes

app.get('/', function(req, res) {
	res.send("Hi I am ImplosiveBot")
})

//LTT Connection

app.get('/webhook/', function(req, res) {
	if (req.query['hub.verify_token'] === "testpasswordforbot") {
		res.send(req.query['hub.challenge'])
	}
	res.send("Wrong Token")
})

app.listen(app.get('port'), function() {
	console.log("running: port")
})
</script>

Thanks!


yeet me into the void daddy linus

 

Link to post
Share on other sites
Posted · Original PosterOP
45 minutes ago, M.Yurizaki said:

Is this client-side code? Because Node.Js isn't for client-side code.

it is backend code


yeet me into the void daddy linus

 

Link to post
Share on other sites
Posted · Original PosterOP
47 minutes ago, MasterCharger said:

i’m going on a lim here but i think you need an extension behind it say express.js

so:

 

 



 

const express = require('express.js')
const bodyParser = require('bodyparser.js')
const request = require('request.js')


 

See https://nodejs.org/api/modules.html

still has the same error

 

let me try it with my code hoster


yeet me into the void daddy linus

 

Link to post
Share on other sites
Posted · Original PosterOP
19 minutes ago, fizzlesticks said:

require is part of Node.js, not JavaScript and js.do doesn't support Node.js code.

thats probably my problem.


yeet me into the void daddy linus

 

Link to post
Share on other sites
Posted · Original PosterOP

ok @fizzlesticks @M.Yurizaki @MasterCharger

 

i ran the code on heroku (the script hoster i use

 

i got this error code:

 

Quote

2017-05-13T18:03:13.837397+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dry-retreat-61258.herokuapp.com request_id=14d18664-53f4-4216-a142-a1626f36e01c fwd="(an ip that i am hiding)" dyno= connect= service= status=503 bytes= protocol=http

2017-05-13T18:03:15.019612+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=dry-retreat-61258.herokuapp.com request_id=fe79d63d-cf81-4f5a-b76c-5abba1710236 fwd="(an ip that i am hiding)" dyno= connect= service= status=503 bytes= protocol=http

Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...

Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...

2017-05-13T17:53:52.091640+00:00 app[web.1]: npm ERR! missing script: start

2017-05-13T17:53:52.091800+00:00 app[web.1]: npm ERR! 

2017-05-13T17:53:52.091877+00:00 app[web.1]: npm ERR! If you need help, you may report this error at:

2017-05-13T17:53:52.091972+00:00 app[web.1]: npm ERR!     <https://github.com/npm/npm/issues>

2017-05-13T17:53:52.101274+00:00 app[web.1]: 

2017-05-13T17:53:52.101444+00:00 app[web.1]: npm ERR! Please include the following file with any support request:

2017-05-13T17:53:52.101546+00:00 app[web.1]: npm ERR!     /app/npm-debug.log

2017-05-13T17:53:52.155890+00:00 heroku[web.1]: Process exited with status 1

2017-05-13T17:53:52.168943+00:00 heroku[web.1]: State changed from starting to crashed

any way that you know how to fix?


yeet me into the void daddy linus

 

Link to post
Share on other sites
Posted · Original PosterOP
7 minutes ago, AUniqueName said:

You're running this in node?

yes


yeet me into the void daddy linus

 

Link to post
Share on other sites

to use require() syntax on the client side you have to use something like System.js. If you are running this with node you have to remove the script tags. If you are using Heroku as a hosting service you have to define a start script inside your package.json. You can simply use

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

  If you are running on a local machine you can use just the node <file.js>


"I speak English very well, bröcklersweiß und nier zu schnell"

-- Probably the favorite quote from bavarian students

Codepen http://codepen.io/MoVo99/

Software Skills

  • HTML, CSS & Client Side JavaScript
  • PHP (Laravel & Lumen)
  • JavaScript (NodeJs with Express)
  • Java (Android SDK; Bukkit SDK)
  • Ruby On Rails (Just learning.... 20%)
Link to post
Share on other sites
Posted · Original PosterOP
43 minutes ago, MoVo said:

to use require() syntax on the client side you have to use something like System.js. If you are running this with node you have to remove the script tags. If you are using Heroku as a hosting service you have to define a start script inside your package.json. You can simply use


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

  If you are running on a local machine you can use just the node <file.js>

now it doesn't want to upload

 

this is what i get back:

 

Quote

Building source:
remote:
remote: -----> Node.js app detected
remote: parse error: Expected separator between values at line 16, column 10
remote:  !     Unable to parse package.json
remote:
remote:
remote: -----> Build failed
remote:
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:       https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote:        If you're stuck, please submit a ticket so we can help:
remote:       https://help.heroku.com/
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to dry-retreat-61258.

 


yeet me into the void daddy linus

 

Link to post
Share on other sites

Please post your package.json here. I can't exactly help if I don't have your package file. But I guess you are missing a comma or a colon. 

{
	"key": "value",
	"key2": "value2"
}

JSON follows a key-value schema. If you are having multiple keys under a parent element you have to write a comma like shown above. The key and the values have to be separated by a colon


"I speak English very well, bröcklersweiß und nier zu schnell"

-- Probably the favorite quote from bavarian students

Codepen http://codepen.io/MoVo99/

Software Skills

  • HTML, CSS & Client Side JavaScript
  • PHP (Laravel & Lumen)
  • JavaScript (NodeJs with Express)
  • Java (Android SDK; Bukkit SDK)
  • Ruby On Rails (Just learning.... 20%)
Link to post
Share on other sites
Posted · Original PosterOP
22 hours ago, MoVo said:

Please post your package.json here. I can't exactly help if I don't have your package file. But I guess you are missing a comma or a colon. 


{
	"key": "value",
	"key2": "value2"
}

JSON follows a key-value schema. If you are having multiple keys under a parent element you have to write a comma like shown above. The key and the values have to be separated by a colon

Will do when I get home


yeet me into the void daddy linus

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Buy VPN

×