Greetings, I acknowledged that when using NUXT programatically with Express it does not picks up nuxt.config.js file.
I used bootstrap 4 for creating my UI using the solution given by @Atinux in https://github.com/nuxt/nuxt.js/issues/178#issuecomment-276207994, and then my requirement was to create a session and make user authentication so I followed Auth Routes example to make use of session and auth but after implementing this all my UI part went wrong as when running node server.js it was not picking up nuxt.config.js where I did all the bootstrap configuration.
My server.js looks like:-
const Nuxt = require('nuxt')
const bodyParser = require('body-parser')
const session = require('express-session')
const express = require('express');
const app = express();
// Body parser, to access req.body
app.use(bodyParser.json())
// Sessions to create req.session
app.use(session({
secret: 'super-secret-key',
resave: false,
saveUninitialized: false,
cookie: { maxAge: 60000 }
}))
// POST /api/login to log in the user and add him to the req.session.authUser
app.post('/api/login', function (req, res) {
if (req.body.username === 'demo' && req.body.password === 'demo') {
req.session.authUser = { username: 'demo' }
return res.json({ username: 'demo' })
}
res.status(401).json({ message: 'Bad credentials' })
})
// POST /api/logout to log out the user and remove it from the req.session
app.post('/api/logout', function (req, res) {
delete req.session.authUser
res.json({ ok: true })
})
// We instantiate Nuxt.js with the options
const isProd = process.env.NODE_ENV === 'production'
const nuxt = new Nuxt({ dev: !isProd })
// No build in production
const promise = (isProd ? Promise.resolve() : nuxt.build())
promise.then(() => {
app.use(nuxt.render)
app.listen(3000)
console.log('Server is listening on http://localhost:3000')
}).catch((error) => {
console.error(error)
process.exit(1)
})
I tried adding bootstrap in default.vue
like
<script>
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap/dist/css/bootstrap-grid.css'
import 'bootstrap/dist/css/bootstrap-reboot.css'
</script>
CSS worked fine but I was not able to add bootstrap.js
as it required jQuery. So my actual issue it to use JQuery in my app and make a beautiful UI using Bootstrap with the ease of NUXT and vue.
Any help is appreciated.
Thanks!