Jump to content

uncaught reference error

piemadd

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!

i like trains 馃檪

Link to comment
Share on other sites

Link to post
Share on other sites

i鈥檓 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

Link to comment
Share on other sites

Link to post
Share on other sites

45 minutes ago, M.Yurizaki said:

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

it is backend code

i like trains 馃檪

Link to comment
Share on other sites

Link to post
Share on other sites

47 minutes ago, MasterCharger said:

i鈥檓 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

i like trains 馃檪

Link to comment
Share on other sites

Link to post
Share on other sites

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

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

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.

i like trains 馃檪

Link to comment
Share on other sites

Link to post
Share on other sites

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?

i like trains 馃檪

Link to comment
Share on other sites

Link to post
Share on other sites

You're running this in node?

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, AUniqueName said:

You're running this in node?

yes

i like trains 馃檪

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

Link to post
Share on other sites

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.

i like trains 馃檪

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Link to post
Share on other sites

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

i like trains 馃檪

Link to comment
Share on other sites

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