Postingan lainnya
Cara running node app.js , saya coba kok gagal
saya running script dibawah ini kok error ya?
const http = require('http'); const express = require('express'); const consolidate = require('consolidate'); const bodyParser = require('body-parser'); const mongoose = require('mongoose');
const routes = require('./routes'); //File that contains our endpoints const socketEvents = require('./socket-events');
const app = express();
app.use(bodyParser.urlencoded({ extended: true, }));
app.use(bodyParser.json({ limit: '5mb' }));
app.set('views', 'views'); // Set the folder-name from where you serve the html page. app.use(express.static('./public')); // setting the folder name (public) where all the static files like css, js, images etc are made available
app.set('view engine', 'html'); app.engine('html', consolidate.handlebars); // Use handlebars to parse templates when we do res.render
// connect to Database const db = 'mongodb://localhost:27017/uberForX'; mongoose.connect(db).then(value => { // Successful connection console.log(value.models); }).catch(error => { // Error in connection console.log(error); });
app.use('/', routes);
const server = http.Server(app); const portNumber = 8000; // for locahost:8000
server.listen(portNumber, () => { // Runs the server on port 8000 console.log(`Server listening at port ${portNumber}`); socketEvents.initialize(server); });
saya running tampilan sbb.:
C:\likeuberx>node app.js internal/modules/cjs/loader.js:638 throw err; ^
Error: Cannot find module 'consolidate' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) at Object. (C:\likeuberx\app.js:3:21) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3)
C:\likeuberx>node app internal/modules/cjs/loader.js:638 throw err; ^
Error: Cannot find module 'consolidate' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) at Object. (C:\likeuberx\app.js:3:21) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3)
C:\likeuberx>
Tanggapan
baca "aturan main" ya, cara bertnaya yang baik, untuk judulnya coba diperbaiki dan cara memasngan kode ada infonya di sana