简体   繁体   English

如何在nodejs中连接javascript文件

[英]how to connect javascript files in nodejs

My problem is not to work javascript. 我的问题是无法使用JavaScript。 my javascript files are in public/javascripts 我的JavaScript文件位于public / javascript中

app.js app.js

app.use(express.static(path.join(__dirname, 'public')));

views/layout.pug views / layout.pug

doctype html
 html
  head
    title Sunghee
    meta(charset='utf-8')
    meta(name='viewport', content='width=device-width, initial-scale=1, shrink-to-fit=no')
    link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css', integrity='sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M', crossorigin='anonymous')
    link(rel='stylesheet', href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css')
    script(src='https://code.jquery.com/jquery-3.2.1.slim.min.js', integrity='sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN', crossorigin='anonymous')
    script(src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js', integrity='sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4', crossorigin='anonymous')
    script(src='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js', integrity='sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1', crossorigin='anonymous')
    //- script(src='https://unpkg.com/jquery@3.2.1/dist/jquery.js')
    script(src='https://code.jquery.com/jquery-3.2.1.min.js')
    link(rel='stylesheet', type='text/css', href='/stylesheets/layout.css')
    script(src='/javascripsts/layout.js')
    block css      
    block script

views/events/new.pug 查看/事件/new.pug

extends ../layout

block css
  link(rel='stylesheet' type='text/css' href='/stylesheets/events/new.min.css')

block script
  script(src='/javascripts/events/new.js')

public/javascripsts/events/new.js 公共/ javascripsts /事件/ new.js

$(function(){
   tinymce.init({
   seletor: '#mytextarea'
  });
});

Not all of the JavaScript files work, as well as this file. 并非所有JavaScript文件都可以使用此文件。 There is "jquery": "^3.2.1" in "dependencies" at package.json What should I do? package.json的“ dependencies”中有"jquery": "^3.2.1" ,我该怎么办?

Mistypings? 造型不好? On your views/layout.pug : 在您的views / layout.pug上

script(src='/javascrip s ts/layout.js') 脚本(SRC = '/的javascrip 小号 TS / layout.js')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM